This Article demonstrate the basic functionality of Lambda Expression in C#(Console Application).
About Lambda Expression
- A lambda expression is an function that contain
many expressions and statements.
- Lambda expression used to create delegates or expression tree types.
- All lambda expressions use the lambda operator =>, which
is read as "goes to".
- The left side of the lambda operator specifies the input parameters.
- The right side holds the expression or statement block
Lambda Expression used to Create two ways.
- Delegates
- Expression Tree Types.
Delegates with Examples
Single Parameter The lambda expression Y => Y
* Y is read "Y goes to Y times Y."
delegate int ADD(int i);
static void Main(string[] args)
{
ADD Delgts = i => i * i;
int K = Delgts(5);
Console.WriteLine(K);
}
Output : 25
Multiple Parameter delegate int ADD(int i,int y );
static void Main(string[] args)
{
ADD Delgts = (i, Z) => i * Z;
int K = Delgts(10, 20);
Console.Write(K);
}
Output :200Lambdas with Standard Query Operators standard query operator, the Count method
int[] Numb = { 15, 14, 11, 13,
19,18,16, 17, 12, 10 };
int
TotalOddno = Numb.Count(n => n % 2 == 1);
Console.Write(TotalOddno);
Output : 5 Conclusion
This article shows basic about LAMBDA Expressions.