我有几个方法都具有相同的参数类型和返回值,但名称和块不同。我想将要运行的方法的名称传递给将调用传递方法的另一个方法。
public int Method1(string){// Do somethingreturn myInt;}
public int Method2(string){// Do something differentreturn myInt;}
public bool RunTheMethod([Method Name passed in here] myMethodName){// Do stuffint i = myMethodName("My String");// Do more stuffreturn true;}
public bool Test(){return RunTheMethod(Method1);}
这段代码不起作用,但这是我正在尝试做的。我不明白的是如何编写RunTheWay代码,因为我需要定义参数。