“="是什么意思?意思? [英] What does "=>" mean?
问题描述
如果这让新手尖叫,请原谅我,但是 =>
在 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.
推荐答案
在 C# 中 lambda 运算符 写成=>"(大声朗读时通常发音为goes to").这意味着左侧的参数被传递到右侧的代码块(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.
因此,如果您有一个 Func 或 Action(或它们的任何具有更多类型参数的表亲),那么您可以为它们分配一个 lambda 表达式,而无需实例化一个委托或使用单独的方法进行延迟处理:>
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:
//creates a Func that can be called later
Func<int,bool> f = i => i <= 10;
//calls the function with 12 substituted as the parameter
bool ret = f(12);
这篇关于“="是什么意思?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!