首页 > 其他 > 详细

Does Lamda expression return value?

时间:2016-01-17 23:09:06      阅读:173      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!