Sunday, January 20, 2008

Demystifying C# 3.0 - Part 7: Expression Trees

source: http://blah.winsmarts.com/2006/05/23/demystifying-c-30--part-7-expression-trees.aspx
Demystifying C# 3.0 - Part 7: Expression Trees
Ending the series with a psshtt bang!! pop!
Posted on 6/30/2006 @ 8:47 PM in #Vanilla .NET 0 comments 3711 views
In this series of Demystifying C# 3.0 we have already covered -
a) Demystifying C# 3.0 - Part 1: Implicitly Typed Local Variables "var"b) Demystifying C# 3.0 - Part 2: Anonymous Typesc) Demystifying C# 3.0 - Part 3: Extension Methodsd) Demystifying C# 3.0 - Part 4: Lambda Expressionse) Demystifying C# 3.0 - Part 5: Object and Collection Initializersf) Demystifying C# 3.0 - Part 6: (LINQ) Query Expression Translation (to C# 3.0)
Thank you to both Eric Wise, and C. Steen for linking. The more people we have look at these posts, the better the overall discussion quality will be.
Okay, so next we will be talking about "Expression Trees". You must read about Lambda Expressions before you read this post.
So in short, Expression trees permit lambda expressions to be represented as data structures, instead of executable code. What that means is, a lambda expression such as
x => x + 1, is executable code. which could also be written as,
Func f = x => x + 1
But,
Expression> e = x => x + 1 ;
In other words, if a lambda expression can convert to a Delegate type "D", it can also convert to an expression tree of type System.Query.Expression.".. if a lambda expression can convert to a Delegate type "D", it can also convert to an expression tree of type System.Query.Expression.. " <-- That fills out that little blurb I left out when discussing Lambda Expressions.This covers the basics of C# 3.0. Next we will be continuing this talk, with a continued discussion on LINQ.

Labels: , , , ,