[英]Inline delegate declaration (c#)
I can't get the following to compile: 我无法得到以下内容进行编译:
var x = new Action(delegate void(){});
Can anyone point out what I'm doing wrong? 谁能指出我做错了什么?
You don't specify a return type when using anonymous methods. 使用匿名方法时,不指定返回类型。 This would work:
这可行:
var x = new Action(delegate(){});
Some alternatives: 一些替代品:
Action x = () => {}; // Assuming C# 3 or higher
Action x = delegate {};
Action x = delegate() {};
var x = (Action) (delegate{});
Why not lambda notation? 为什么不用lambda表示法?
Action myAction= (Action)(()=>
{
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.