lambda Advanced Search

1. What is the lambda expression: the Lambda expressions, is a simplified anonymous function can be used to create a delegate or an expression tree. Secondly, Lambda expressions may be passed as an argument, or a function which acts on the value returned by the function call after the call to use. Lambda expressions are often used in LINQ.

2.Lambda expression: expression => right operator, called "lambda expression." LINQ and lambda expressions used in constructing expression tree, it also allows to return results. Basic forms: (input parameters) => expression.

3.lambda statements above and compared to lambda expressions, but a plurality of braces ( "{}").  

Basic forms: (input parameters) => {} expression.

4. By async and await keywords, we can easily and quickly create lambda expressions and statements that include asynchronous processing.

1) Async

2) Await

5. In Linq use Lambda

Many  LINQ parameters delegate type is a kind of parameters, such as  Func <T, TResult> , you can define input parameters and return types.

public delegate TResult Func<TArg0, TResult>(TArg0 arg0)  

Func <int, bool> represents: int input parameters, bool return value.

Func <int, int, bool> represents: int two input parameters, return to a bool value.

Example:

1) Func<int, bool> myFunc = x => x == 250;  

2) was resulted = myFunc (1314);

6. the Lambda features

1) Lambda contains the number of input parameters, the same number of parameters must be included in the delegate type.

2) Lambda each input parameter, it must be able to delegate its corresponding parameter type by implicit conversion

3) Lambda return value (if any) must be able to implicitly convertible to the return type of the delegate

 

Guess you like

Origin www.cnblogs.com/zyx13966104797/p/11201726.html