Pass Method as Parameter using C#

后端 未结 12 1377
不知归路
不知归路 2020-11-21 23:30

I have several methods all with the same parameter types and return values but different names and blocks. I want to pass the name of the method to run to another method tha

12条回答
  •  忘了有多久
    2020-11-22 00:13

    public static T Runner(Func funcToRun)
    {
        //Do stuff before running function as normal
        return funcToRun();
    }
    

    Usage:

    var ReturnValue = Runner(() => GetUser(99));
    

提交回复
热议问题