开发者

how to convert lambda expression to object directly?

开发者 https://www.devze.com 2022-12-22 19:02 出处:网络
I have to do through Action like this: Action acti开发者_如何学Goon = () => { ..// }; object o = action;

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

精彩评论

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