码迷,mamicode.com
首页 > 其他好文 > 详细

Does Lamda expression return value?

时间:2016-01-17 23:12:08      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

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.

 

Does Lamda expression return value?

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!