Put Multiple Statements in a Statement Lambda

Download c# eBook

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.

Stats

Contributors: 2
2017-04-27
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook