Thursday, March 20, 2008 10:24 AM
The Evolution of Lambda Functions in C#
Howard Dierking over at MSDN has a really interesting Blog post entitled "Lambda, Lambda, Lambda!" in which he described the evolution of the lambda function in C#.
It seems fairly simple on the surface: 1.0 Introduced Delegates, 2.0 Introduced Anonymous Methods, and 3.0 Introduced Lambda Expressions.
I had been wondering what made Lambda Expressions in C# so much better then Delegates or Anonymous Methods other then the shortened syntax. It turns out that the really interesting thing about Lambdas is how it is possible to parse and manipulate them on the fly:
BinaryExpression expBody = lambdaExp.Body as BinaryExpression;
Once you have the BinaryExpression you can then break it apart and parse it as Nodes in an Expression Tree. It is then possible to manipulate it freely in this context.
If you want to take it one step further, you can even construct expressions on the fly as Bart De Smet describes in this post.
Wow, all this new Lambda functionality is pretty revolutionary.