Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of LINQ expression Tree

Shulou Source: shulou.com Published: 2022-06-02 11:45:20 11月13日 Update

Editor to share with you the example analysis of the LINQ expression tree, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Linq.Expressions Namespace ConsoleApplication3 {class Program {static void Main (string [] args) {/ / important class * / / BinaryExpression: dual, binary The expression / / ParameterExpression consists of two things: get the parameter IQueryable a = Enumerable.Range (0, 1000). AsQueryable () Expression expression = r = > r < 20 & & r = = 2; / / = query expression tree (expression) parameter (only one parameter) foreach (var item in expression.Parameters) {Console.WriteLine ("parameter: {0}, node type: {1}", item, item.NodeType) / / output: parameters: r, node type: Lambda} / / = query expression tree (expression) body part / / output: body part: (r < 20 AndAlso r = = 2), node type: Lambda Console.WriteLine ("body part: {0}, node type: {1}", expression.Body, expression.NodeType) / / the left body of the query expression tree (expression) / / output: (r < 20) to cast the type to the BinaryExpression type Console.WriteLine (BinaryExpression) expression.Body) .left) / / = query the variable type on the left side of the main part of the expression tree (expression) / / Int32 Console.WriteLine (BinaryExpression) ((BinaryExpression) expression.Body) .left) .Left.Type.Name); Console.ReadKey ();} above is all the content of the article "sample Analysis of LINQ expression Tree". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Expression type body parameter part node query article output example analysis content important not much thing two variables only most more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia Redmi Shulou Information Microsoft