Possible Duplicate:
What is the => token called?
What is the name of this operator in C#?
Possible Duplicate:
What is the => token called?
What is the name of this operator in C#?
它在 MSDN 文档中称为lambda 运算符。
所有 lambda 表达式都使用 lambda 运算符 =>,读作“goes to”。lambda 运算符的左侧指定输入参数(如果有),右侧保存表达式或语句块。lambda 表达式 x => x * x 读作“x 乘以 x”。可以将此表达式分配给委托类型,如下所示:
作为旁注,在 Ruby 中被称为“hashrocket”运算符。
如果您在 LINQ 的上下文中交谈,那就是lamdba 运算符。
如 ...
var selectedValues = myList.Where(v=>v.Name="Matt");
您可以在自己的方法中使用这些来代替委托。可能的用途包括这样的东西......
void DoWork<T>(T input, Func<T, bool> doAction, Action<T> action)
{
if (doAction(input))
action(input);
}
...上述方法的用法看起来像...
DoWork(5, i=>i>1, v=>Console.WriteLine(v));
...因为 5 大于 1 这将在控制台上显示 5。
FWIW,对于 Rubyists,这个操作符被称为“哈希火箭”。(甚至还有一家叫这个名字的公司。)