=>
是什么意思?以下是代码片段:Dispatcher.BeginInvoke((Action)(() => { trace.Add(response); }));
lambda表达式是匿名委托的简化语法,它读作“goes to”。等同于Dispatcher.BeginInvoke((Action)delegate() { trace.Add(response); });
=>是一个lambda表达式操作符,表示代码是一个lambda表达式。
( param ) => expr(int x) = > { return x + 1 };
或者
param => exprx=> x + 1;>
* 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.
阅读更多: Lambda表达式
这个 "=>" 在 C# 中表示使用 lambda 表达式语法。
自 Visual Studio 2008 的 .NET 3.5 (C# 3.0) 起,该语法已经可用。这是 C# 中 lambda 表达式的 MSDN 官方文档。
上面的代码与 C# 2.0 中已经可用的匿名委托相同。
您的代码:
Dispatcher.BeginInvoke((Action)(() => { trace.Add(response); }));
被翻译成:
Dispatcher.BeginInvoke(new delegate () { trace.Add(response); });
这两个代码本质上具有相同的语义。
Dispatcher.BeginInvoke((Action)(() => trace.Add(response) ));
这是一个类似于“goes to”的lambda运算符。