I have multiple methods, all of which have the same parameter types and return values but varied in their names and blocks. I'd like to provide the name of the method I want to run to another method, which will then call the passed method.
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);
}
This code doesn't work, but it's what I'm attempting to accomplish. I'm not sure how to create the RunTheMethod code because I need to define a parameter.