In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the example analysis of Linq lambda expressions, 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!
Linq lambda expression
If you have been familiar with the new features of C # 3.0, you should know that a new syntax structure called lambda expression (Linq lambda expressions / anonymous functions) has been introduced in C # 3.0. For those who don't know this yet, you can also take a look at MSDN, the Linq lambda expression. Linq lambda expressions can be assigned to a delegate type, such as the built-in delegate type of a series of Action, Func, and so on, or to an Expression type, such as the following Linq lambda expression:
X = >-x
When it is assigned directly to a variable of type Func, the C # compiler compiles its contents to a static method and creates a reference of the corresponding type to assign to the variable.
Static class Program {static void Main (string [] args) {Func negateFunc = x = >-x;}}
The C # compiler compiles to code similar to the following:
Internal static class Program [CompilerGenerated] private static int breadbasket 0 (int x) {return-x;} private static void Main (string [] args) {Func negateFunc = new Func (breadbasket 0);}}
(it actually involves caching the delegate, which is omitted here. In addition, it is compiled to a static method because the Linq lambda expression does not use any "free variables", that is, variables that are neither parameters or local variables nor members of the class. In the existing C # compiler implementation, if an anonymous function uses "this", then the corresponding method will be a member method; if other free variables are used, a private inner class will be generated to hold the free variables used by the anonymous function, and the corresponding method of the anonymous function will be generated in this inner class. Here, as an example, choose the simplest case to introduce. )
After compiling an Linq lambda expression into an actual function, the MSIL bytecode in it can be understood and executed by CLR. This is enough to implement in-memory query, such as LINQ-to-Objects, LINQ-to-DataSet, and so on. However, other platforms do not understand MSIL, so it is very difficult to analyze and execute the function. For example, if you want an Linq lambda expression to execute on SQL Server, how do you make SQL Server understand it?
Expression tree and Linq lambda expressions
The reason why MSIL is not easy to analyze is that it converts the program code which was originally a tree structure into a linear structure, which loses some information, mainly because it loses the "structure" of the program code, which is closer to the bottom and reduces the degree of abstraction.
We know that the program source code corresponds to a specific grammar tree (concrete syntax tree), each leaf node corresponds to a morpheme in the code, on which are various grammatical structures, such as expressions, statements, declarations, definitions and so on. Abstract grammar tree (abstract syntax tree,AST) removes some redundant information such as keywords and parentheses on the basis of the concrete syntax tree to make the tree cleaner and easy to analyze without losing any useful information.
The above is all the content of the article "sample Analysis of Linq lambda expressions". 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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.