1. Lambda expression: input on the left and input on the right Code
In LINQ, lambda expressions have two special signatures. A Lambda expression that returns a Boolean value is called a predicate. Only one parameter of a specific type is accepted, but a different type is returned, which is called projection.
2. Lambda expressions
Lambda expressions encapsulate code, but do not use keywords, normal function signatures, or formal function bodies
Lambda is defined using the lambda operator (=>). The left side is the input, and the right side is the code, similar to the anonymous method.
3. Lambda expression directory tree
In the expression directory tree, the code is data. More precisely, the code in the expression directory tree is filled with Lambda expressions. As data, you can modify or even edit the code at runtime.
The expression directory tree is represented by the expression type, and the expression object is initialized using the lambda expression. binaryexpression encapsulates a Binary Expression, and then Program Extract the topic, left parameter, and right parameter of the expression.
Finally, compile and execute the program.
Expression <func <int, Int, int> product = (x, y) => X * Y;
Binaryexpression body = (binaryexpression) product. Body;
Parameterexpression left = (parameterexpression) body. Left;
Parameterexpression right = (parameterexpression) body. Right;
Console. writeline ("{0} \ nleft: {1} Right: {2}", body, left, right );
VaR Lambda = product. Compile ();
Console. writeline (lambda (3, 2 ));
4. C # language query syntax