Lambda expressions are anonymous functions that can contain expressions and statements and can be used to create a delegate or expression tree type.
All Lambda expressions use the Lambda operator =>, which reads "goes ". The left side of the Lambda operator is the input parameter (if any), and the right side contains the expression or statement block.
The basic form of Lambda expressions is:
[Csharp]
(Explicitly-typed-parameter-list) =>{ statements}
[Csharp]
(String text) =>{ return text. Length ;};
If the statement contains only one expression, you can simplify the lambda expression to the following form:
[Csharp]
(Explicitly-typed-parameter-list) => expression
[Csharp]
(String text) => text. Length
In general, the compiler can deduce the parameter type to simplify the form below:
[Csharp]
(Implicitly-typed-parameter-list) => expression
[Csharp]
(Text) => text. Length www.2cto.com
Furthermore, if the lambda expression contains only one parameter, we can remove the parentheses to simplify the form below:
[Csharp]
Parameter-name => expression
[Csharp]
Text => text. Length