Does Lamda expression return value?

Basically, the compiler does this for you.

If you write a lambda as a single statement (and don't include block notation, ie: {}), the returned value is the value of the expression written.

In your case, this:

Func<int,int> square = x => x*x;

Is seen to only have one expression (x*x), so it is treated as:

Func<int,int> square = (int x) => { return x*x; };

If you want to have more than a single statement in the lambda, you'd need the braces, in which case you'd have to write the return for it to compile correctly.

原文地址:https://www.cnblogs.com/askdong/p/5137887.html