C# Language Put Multiple Statements in a Statement Lambda

Download C# Language for free

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.

Lambda Expressions