Difference between expression lambda and statement lambda

ckv picture ckv · Jun 21, 2013 · Viewed 7.6k times · Source

Is there a difference between expression lambda and statement lambda?

If so, what is the difference?

Found this question in the below link but could not understand the answer What is Expression Lambda?

C# interview Questions

The answer mentioned in that link is this A lambda expression with an expression on the right side is called an expression lambda.

Per my understanding always the expression is in the right hand side only. That is why I am asking this question. Is there anything I am unaware of?

Answer

Eric Lippert picture Eric Lippert · Jun 21, 2013

This is indeed confusing jargon; we couldn't come up with anything better.

A lambda expression is the catch-all term for any of these:

x => M(x)
(x, y) => M(x, y)
(int x, int y) => M(x, y)
x => { return M(x); }
(x, y) => { return M(x, y); }
(int x, int y) => { return M(x, y); }

The first three are expression lambdas because the right hand side of the lambda operator is an expression. The last three are statement lambdas because the right hand side of the lambda operator is a block.

This also illustrates that there are three possible syntaxes for the left side: either a single parameter name, or a parenthesized list of untyped parameters, or a parenthesized list of typed parameters.