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

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

问题描述

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

Is there a difference between expression lambda and statement lambda?

如果是这样,有什么区别?

If so, what is the difference?

在以下链接中找到了此问题,但无法理解答案 什么是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); }

前三个是 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.

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

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