C# delegate not bound to an instance?

后端 未结 4 1944
盖世英雄少女心
盖世英雄少女心 2021-01-04 08:47

Is there a way to store a delegate without binding it to an object like how you can with a MethodInfo? Right now I am storing a MethodInfo so I can give it the object to cal

4条回答
  •  北海茫月
    2021-01-04 09:18

    Why not simply

    Action unbound = (This, str) => This.Method(str);
    

    so you can

    unbound(instanceA, "hello");
    unbound(instanceB, "world");
    

    or even

    Action bound = str => unbound(instanceC, str);
    

提交回复
热议问题