开发者

Inline delegate declaration (c#)

I can't get the following to comp开发者_运维技巧ile:

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?

Action myAction= (Action)(()=>
{
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜