Difference between expression lambda and statement lambda

后端 未结 4 1367
长情又很酷
长情又很酷 2021-02-01 03:38

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 understa

4条回答
  •  春和景丽
    2021-02-01 04:16

    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.

提交回复
热议问题