Lambdaexpressions are anonymous functions that contain expressions or sequence of operators. All lambda expressions use the lambda operator =>, that can be read as “goes to” or “becomes”. The left side of the lambda operator specifies the input parameters and the right side holds an expression or a code block that works with the entry parameters. Usually lambda expressions are used as predicates or instead of delegates (a type that references a method). Expression Lambdas Parameter => expression Parameter-list => expression Count => count + 2; Sum => sum + 2; n => n % 2 == 0 The lambda operator => divides a lambda expression into two parts. The left side is the input parameter and the right side is the lambda body.
using System; using System.Collections.Generic; using System.Linq; public static class Lambda { public static void Main() { List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 }; List<int> evenNumbers = list.FindAll(x => (x % 2) == 0); Console.Write("Even numbers :"); foreach (var num in evenNumbers) {
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Lambda expressions are anonymous functions that contain expressions or sequence of operators. All lambda expressions use the lambda operator =>, that can be read as “goes to” or “becomes”.
The left side of the lambda operator specifies the input parameters and the right side holds an expression or a code block that works with the entry parameters. Usually lambda expressions are used as predicates or instead of delegates (a type that references a method).
Expression Lambdas
Parameter => expression
Parameter-list => expression
Count => count + 2;
Sum => sum + 2;
n => n % 2 == 0
The lambda operator => divides a lambda expression into two parts. The left side is the input parameter and the right side is the lambda body.
c