Put Multiple Statements in a Statement Lambda C# with Example



Put Multiple Statements in a Statement Lambda C# with Example

Unlike an expression lambda, a statement lambda can contain multiple statements separated by semicolons. 
delegate void ModifyInt(int input); 
ModifyInt addOneAndTellMe = x => 
{ 
int result = x + 1; 
Console.WriteLine(result); 
}; 
Note that the statements are enclosed in braces {}. 
 

Remember that statement lambdas cannot be used to create expression trees. 

0 Comment's

Comment Form

Submit Comment