开发者

how to convert lambda expression to object directly?

I have to do through Action like this:

Action acti开发者_如何学Goon = () => { ..// };
object o = action;

any way to do this:

object o = () =>{};  //this doesn't compile


What about:

object o = (Action) (() => { ... });

Though I don't really know why you'd want to store it as an object in the first place...


Weeeell, delegates are objects, but lambdas aren't.

This object o = (Action)(() => {}); will compile, but I don't know if it looks any better.


Another option, not all that different:

object o = new Action(() => { });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜