So far I’ve bought into the “All of C# 3.0’s new language features are just syntatic sugar” view. Today I realized that this sugar has some kick to it.
If Lambda Functions are syntatic sugar, then Expression Trees are habanero peppers.
A lambda function is a new way to declare an anonymous delegate, which is effectively a function pointer. Lambda functions are compiled into executable code.
Expression Trees are data structures that contain descriptions of lambda functions. They convert your code into data. Somewhere down the road in your application a block of code will call Compile() on the expression tree to get a reference to the lambda function and then call Invoke() to execute the lambda.
I found these articles helped me understand Expression Trees:
Expression trees are used heavily by Linq and Linq to Sql. It’s important to understand Expression Trees if you want to develop your own Linq IQueryProvider, which is not a trivial task!
Posted by Rob under .Net & Development | 2 Comments »