C# has two types of anonymous functions: anonymous methods and Lamda expressions. Anonymous methods and Lambda expressions can define a method implementation inline; but, the anonymous method explicitly defines the parameter and return type for the method. Lambda expressions, however, use the type inference that allows the .NET compiler to infer the variable type based on context.

To create a lambda expression, specify the input parameters on the left side of the lambda operator =>, and the expression or statement block on the other side. For example, if the generic list: List numbers = new List{1,2,3,4,5,6,7}; the lambda expression: var evens = numbers.FindAll(n => n % 2 == 0); returns even numbers (2, 4, 6) from the modulus division operation.

  Below is a list of numbers separated by commas. Click to see them divided into even and odd lists:

  Numbers List:   

  Odd List:         

  Even List:         

  

View the Lamda Code PDF