#1,174 – Assigning a Lambda Expression to an Expression Tree

You can assign a lambda expression to either an instance of a delegate type or to an expression tree based on a compatible delegate type.  An expression tree is just an in-memory representation of an expression, encoding the expression as a tree.  This allows you to interact with the expression as a data structure.

            // Assign to delegate type
            Func<int, int> doubleMe = (i) => 2 * i;

            // Assign to expression tree
            // (using System.Linq.Expressions)
            Expression<Func<int, int>> doubleMeExpr = (i) => 2 * i;

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #1,174 – Assigning a Lambda Expression to an Expression Tree

  1. Pingback: Dew Drop – September 3, 2014 (#1847) | Morning Dew

Leave a comment