## Demystifying C# 3.0 - Part 7: Expression Trees

Posted on 6/30/2006 @ 8:47 PM in #Vanilla .NET by Sahil Malik | Feedback | 9440 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 Types__

c) __Demystifying C# 3.0 - Part 3: Extension Methods__

d) __Demystifying C# 3.0 - Part 4: Lambda Expressions__

e) __Demystifying C# 3.0 - Part 5: Object and Collection Initializers__

f) __ 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<int,int> f = x => x + 1

But,

Expression<Func<int,int>> 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<D>.*".. if a lambda expression can convert to a Delegate type "D", it can also convert to an expression tree of type System.Query.Expression<D>.. " <-- *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.