简体   繁体   中英

how to convert lambda expression to object directly?

I have to do through Action like this:

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

any way to do this:

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

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

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

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...

另一种选择,并非完全不同:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM