8/13/2018 - 4:02 PM

Expression Lambdas

A lambda expression with an expression on the right side of the => operator is called an expression lambda. Expression lambdas are used extensively in the construction of Expression Trees.

Full documentation: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions

// General form of a lambda expression:
// (input-parameters) => expression

//The parentheses are optional only if the lambda has one input parameter; eg..
x => x * x

// otherwise they are required. Two or more input parameters are separated by commas enclosed in parentheses:
(x, y) => x == y

// Sometimes it is difficult or impossible for the compiler to infer the input types. When this occurs, 
// you can specify the types explicitly
(int x, string s) => s.Length > x

// Specify zero input parameters with empty parentheses:
() => SomeMethod()