Convert Action to Action<object>

前端 未结 4 875
感动是毒
感动是毒 2020-12-11 14:19

I am stuck.

How do I convert the Action to an Action in C#?

Regards Magnus

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 15:11

    I assume you have something like this:

    void Foo(Action action) { }
    
    Action myaction;
    
    
    

    And want to convert myaction so you can pass it to Foo.

    That doesn't work.

    Foo can pass any object to the action whose type derives from object. But myaction accepts only objects that derive from something.

    提交回复
    热议问题