的含义()=>操作员在C#中,如果存在
问题描述:
我这里读了这个有趣的线上,由乔恩飞碟双向的答案。
I read this interesting line here, in an answer by Jon Skeet.
有趣的线是这个,他在那里使用委托主张:
The interesting line is this, where he advocated using a delegate:
Log.Info("I did something: {0}", () => action.GenerateDescription());
问题是,这是什么()=>运营商,我不知道?我试图谷歌搜索,但因为它是由符号的谷歌不可能有很大帮助,真的。难道我尴尬想念这里的东西吗?
Question is, what is this ()=> operator, I wonder? I tried Googling it but since it's made of symbols Google couldn't be of much help, really. Did I embarrassingly miss something here?
答
此介绍不带参数的lambda函数(匿名委托),它相当于基本上速记为:
This introduces a lambda function (anonymous delegate) with no parameters, it's equivalent to and basically short-hand for:
delegate void () { return action.GenerateDescription(); }
您还可以添加参数,这样:
You can also add parameters, so:
(a, b) => a + b
这是大致相当于:
delegate int (int a, int b) { return a + b; }