Lambda Expressions in C#

 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 Expressions can be of two types: 

Expression Lambda: Consists of the input and the expression.

Syntax:

input => expression;

Statement Lambda: Consists of the input and a set of statements to be executed.

Syntax:

input => { statements };


No comments:

Post a Comment