28 April 2010

Lambda Expressions - The Shuttle _Tidirium_ of .NET

Actually, I just said that 'cause I wanted to get my Star Wars geek on. Today I ran across this article while trying to wrap my head around lambda expressions. I was trying to wrap my head around lambda expressions because they're cool (that is, useful and geeky). So, to sum up the artical (without using his example) let's look at some code I just modified to use Lambdas. Old Code:

User u = (from u1 in Users where u1.UserName == userName select u1).First(); CurrentTicket.Reasign(u);

New Code:

CurrentTicket.Reassign(Users.ToList(). Where(u => u.UserName == userName).First());

As the article points out, these are really saying the same thing. The Lambda Expression is just more concise.

No comments:

Post a Comment