简体   繁体   English

'=>'是什么意思?

[英]What does '=>' mean?

What does => means? =>是什么意思? Here's a code snap: 这是一个代码快照:

Dispatcher.BeginInvoke((Action)(() => { trace.Add(response); }));

it's lambda expression which is the simplified syntax of anonymous delegate. 它是lambda表达式,它是匿名委托的简化语法。 it reads 'goes to'. 它写着'去'。 equivalent to Dispatcher.BeginInvoke((Action)delegate() { trace.Add(response); }); 相当于Dispatcher.BeginInvoke((Action)delegate() { trace.Add(response); });

=> is lambda expression operator which indicate that the code is lambda expression. =>是lambda表达式运算符,表示代码是lambda表达式。

( param ) => expr(int x) = > { return x + 1 };

or 要么

param => exprx=> x + 1;>

What is Lambda expression ? 什么是Lambda表达式?

* Lambda expression is replacement of the anonymous method avilable in C#2.0 Lambda 
  expression can do all thing which can be done by anonymous method.
* Lambda expression are sort and function consist of single line or block of statement.

Read more : Lambda Expressions 阅读更多: Lambda表达式

=> is an operator called Lambda Operator =>是一个名为Lambda Operator的运算符

It is used for creating a lambda expression 它用于创建lambda表达式

它是一个lambda运算符,读起来像“去”

This "=>" means the use of lambda expression syntax in C#. 这个“=>”表示在C#中使用lambda表达式语法。

This syntax is available since Visual Studio 2008 in .NET 3.5 (C# 3.0). 自.NET 3.5中的Visual Studio 2008(C#3.0)以来,此语法可用。 This is the MSDN official documentation of lambda expression in C# . 这是C#中lambda表达式MSDN官方文档

The code above is the same as anonymous delegate in already available since C# 2.0 上面的代码与自C#2.0以来已经可用的匿名委托相同

Your code: 你的代码:

Dispatcher.BeginInvoke((Action)(() => { trace.Add(response); })); 

is translated into: 被翻译成:

Dispatcher.BeginInvoke(new delegate () { trace.Add(response); });

Those two codes essentially have the same semantics. 这两个代码基本上具有相同的语义。

值得注意的是,单个表达式lambda不需要身体周围的{},也不需要分号,所以你可以简化你的代码(略)。

Dispatcher.BeginInvoke((Action)(() => trace.Add(response) ));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM