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)(()=>
{
});
精彩评论