“==”是什么意思? 意思是?
如果这让新手尖叫,请原谅我,但是 =>
在 C# 中意味着什么? 我上周参加了一次演讲,这个运算符(我认为)是在 ORM 的上下文中使用的。 在我回到我的笔记之前,我并没有真正关注语法的细节。
Forgive me if this screams newbie but what does =>
mean in C#? I was at a presentation last week and this operator (I think) was used in the context of ORM. I wasn't really paying attention to the specifics of syntax until I went back to my notes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在 C# 中,lambda 运算符 写作“=>” (大声朗读时通常发音为“去”)。 这意味着左侧的参数被传递到右侧的代码块(lambda 函数/匿名委托)中。
因此,如果您有一个 Func 或 Action(或任何具有更多类型参数的表兄弟),那么您可以为它们分配一个 lambda 表达式,而不需要实例化委托或使用单独的方法来进行延迟处理:
In C# the lambda operator is written "=>" (usually pronounced "goes to" when read aloud). It means that the arguments on the left are passed into the code block (lambda function / anonymous delegate) on the right.
So if you have a Func or Action (or any of their cousins with more type parameters) then you can assign a lambda expression to them rather than needing to instantiate a delegate or have a separate method for the deferred processing:
由于还没有人提到它,因此在 VB.NET 中您可以使用 function 关键字而不是 =>,如下所示:
Since nobody mentioned it yet, in VB.NET you'd use the function keyword instead of =>, like so:
它是声明 lambda 的简写。
与写作(有点)相同:
在上下文中:
这与写作(有点)相同:
只需不给它一个名称,它就允许您内嵌声明一个函数,称为“匿名”功能。
It's shorthand for declaring a lambda.
is (sort of) the same as writing:
In the context of:
which is (sort of) the same as writing:
Just without giving it a name, it allows you to declare a function in-line, known as an "anonymous" function.
当大声说出时,该运算符是 lambda(转到)运算符,它有助于定义您在 lambda 中定义的匿名委托。
常见的情况是使用事件处理程序。 您经常会遇到由 lambda 使用以下代码处理的页面加载类型事件:
您已经使用 lambda 表达式定义了一个匿名处理 Loaded 事件的方法(它没有名称)。 它将读作“o,e 转到...使用 foo 的方法定义”。
When said aloud the operator is the lambda (goes to) operator which helps to define the anonymous delegate that you're defining in the lambda.
A common place to see this is with an event handler. You will often have a a page load type event that is handled by a lambda with the following code:
You've defined a method handling the Loaded event anonymously (it doesn't have a name) by using a lambda expression. It would read as "o, e goes to ... method definition with foo."
这是“lambda 运算符”,您可以将其读作“前往”。 假设您有这样的语句:
您可以替换“=>” 在你的脑海中这样想:
正如你所看到的,它提供了一种速记法。 编译器会计算出您传递的变量的类型,并允许您摆脱函数签名和将签名变量传递到的代码的括号。
This is the "lambda operator", and you read it as "goes to". Say you had the statement:
You can replace the "=>" in your mind with this:
As you can see, it offers a heck of a shorthand. The compiler figures out the type of the variable that you're passing, and allows you to get rid of the function signature and bracketing for the code that you're passing the signature variables into.
它是一个 lambda 运算符,是 lambda 表达式 的一部分。
It's a lambda operator, part of a lambda expression.
它是声明匿名函数的语法,在 C# 中称为“lambda 表达式”。
例如,
(int p) => p * 2
表示一个函数,它接受一个整数并将其乘以二。It's syntax to declare an anonymous function, known in C# as a "lambda expression."
For example,
(int p) => p * 2
represents a function that takes an integer and multiplies it by two.