我有几个方法都具有相同的签名(参数和返回值),但不同的名称和方法的内部是不同的。我想传递该方法的名称运行到另一个方法,将调用传入的方法。
public int Method1(string){ ... do something return myInt;}public int Method2(string){ ... do something different return myInt;}public bool RunTheMethod([Method Name passed in here] myMethodName){ ... do stuff int i = myMethodName("My String"); ... do more stuff return true;}public bool Test(){ return RunTheMethod(Method1);}此代码不起作用,但这是我想要做的。我不明白的是如何编写RunTheMethod代码,因为我需要定义参数。
相似问题