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?
An expression lambda is a type of lambda that has an expression to the right of the lambda operator. The other type of lambda expression is a statement lambda because it contains a statement block {...} to the right side of the expression. Expression lambda takes the form: number => (number % 2 == 0)
In particular, a lambda function has the following characteristics: It can only contain expressions and can't include statements in its body. It is written as a single line of execution.
Language Integrated Query (LINQ) is feature of Visual Studio that gives you the capabilities yo query on the language syntax of C#, so you will get SQL kind of queries. And Lambda expression is an anonymous function and is more of a like delegate type.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With