zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    寒假13
    寒假作业十二
    寒假12
    寒假作业十一
    寒假11
    寒假作业九
    寒假10
    寒假作业九
    寒假9
    寒假作业八
  • 原文地址:https://www.cnblogs.com/askdong/p/5137887.html
Copyright © 2011-2022 走看看