且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

表达式lambda与语句lambda之间的区别

更新时间:2023-10-05 14:44:22

这确实是令人困惑的行话;我们无法提出更好的建议.

This is indeed confusing jargon; we couldn't come up with anything better.

一个 lambda表达式是其中任何一个的笼统术语:

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); }

前三个是 expression lambdas ,因为lambda运算符的右侧是一个表达式.最后三个是 statement lambdas ,因为lambda运算符的右侧是一个 block .

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.