“ =”是什么意思?意思? [英] What does "=>" mean?

查看:179
本文介绍了“ =”是什么意思?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我,如果这叫新手,但是 => 在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运算符写为 =>(通常发音为<<> )。这意味着左侧的参数将传递到右侧的代码块(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屋!

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