That is, Lambda Expression only provides the facility to specify the syntax of the Anonymous Method in a simple way. In place of the Anonymous Method, we can also use Lambda Expressions, which is more convenient to use than Anonymous Methods.
LINQ Lambda Expressions Syntax
(Input Parameter) => Method Expression
Lambda Expression is dynamic variable and decides the type in compile time.
intAry.Where( x => x%2 == 0 );
in this example x is dynamic variable, and this expression { x%2 == 0 } check the x is even or odd.
Example
using System; using System.Linq; using System.Collections.Generic; class MyProgram { static void Main(string[ ] args) { int[] intAry = {45,78,5,896,4,5,8,65,99,66,55,88,5,558,56,55,45,23}; Console.WriteLine('Even list '); var Evenlist = intAry.Where( x => x%2 == 0 ); Evenlist.ToList().ForEach(x => Console.Write(x+ ', '));
Console.WriteLine('\nOdd list '); var Oddlist = intAry.Where( x => x%2 != 0 ); Oddlist.ToList().ForEach(x => Console.Write(x + ', ')); } }
Output
Even list 78, 896, 4, 8, 66, 88, 558, 56, Odd list 45, 5, 5, 65, 99, 55, 5, 55, 45, 23,
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
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.
That is, Lambda Expression only provides the facility to specify the syntax of the Anonymous Method in a simple way. In place of the Anonymous Method, we can also use Lambda Expressions, which is more convenient to use than Anonymous Methods.
LINQ Lambda Expressions Syntax
Lambda Expression is dynamic variable and decides the type in compile time.
intAry.Where( x => x%2 == 0 );
in this example x is dynamic variable, and this expression { x%2 == 0 } check the x is even or odd.
Example
Output