Expression Trees (C # and Visual Basic)

Source: Internet
Author: User

Https://msdn.microsoft.com/en-us/library/bb397951.aspx

Expression trees represent code in a tree-like the data structure, where each node was an expression, for example, a method cal L or a binary operation such as x < Y.

You can compile and run code represented by expression trees.

This enables dynamic modification of executable code, the execution of LINQ queries in various databases, and the creation of dynamic queries.

For more information about expression trees in LINQ, see how to:use Expression trees to Build Dynamic Queries (C # and Vis UAL Basic).

Expression trees is also used in the Dynamic Language runtime (DLR) to provide interoperability between dynamic languages The. NET Framework and to enable compiler writers to emit expression trees instead of Microsoft intermediate language (MSIL).

For more information on the DLR, see Dynamic Language Runtime Overview.

You can have the C # or Visual Basic compiler create an expression tree for your based on an anonymous anonymous lambda expression,

Or you can create an expression trees manually by using the System.Linq.Expressions namespace.

Creating Expression Trees from Lambda Expressions

When a lambda expression was assigned to a variable of type expression<TDelegate>, the compiler emits issued, radiated; Publish code to build a expression tree that represents the lambda expression.

The C # and Visual Basic compilers can generate expression trees only from expression lambdas (or Single-line lambdas).

It cannot parse statement lambdas (or multi-line lambdas).

For more information on lambda expressions in C #, see Lambda Expressions (C # Programming Guide);

For Visual Basic, see Lambda Expressions (Visual Basic).

The following code examples demonstrate how to has the C # and Visual Basic compilers create an expression tree that repre Sents the lambda expression num = num < 5 (C #) or Function (num) num < 5 (Visual Basic).

expression<func<intbool5;

Expression Trees (C # and Visual Basic)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.