表达式 lambda 和语句 lambda 之间的区别 [英] Difference between expression lambda and statement lambda

查看:43
本文介绍了表达式 lambda 和语句 lambda 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表达式 lambda 和语句 lambda 之间有区别吗?

Is there a difference between expression lambda and statement lambda?

如果有,有什么区别?

在下面的链接中找到了这个问题,但无法理解答案什么是表达式 Lambda?

Found this question in the below link but could not understand the answer What is Expression Lambda?

C# 面试题

该链接中提到的答案是这个右侧有表达式的 lambda 表达式称为表达式 lambda.

The answer mentioned in that link is this A lambda expression with an expression on the right side is called an expression lambda.

根据我的理解,表达式始终仅在右侧.这就是我问这个问题的原因.有什么我不知道的吗?

Per my understanding always the expression is in the right hand side only. That is why I am asking this question. Is there anything I am unaware of?

推荐答案

这确实是令人困惑的行话;我们想不出更好的办法.

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

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

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.

这篇关于表达式 lambda 和语句 lambda 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆