I want to pass a method ( of void return type and with no input arguments) as parameter using C#. Below is my sample code. How can I do it ?
public void Method1()
{
... do something
}
public int Method2()
{
... do something
}
public void RunTheMethod([Method Name passed in here] myMethodName)
{
myMethodName();
... do more stuff
}
System.Action will fit the bill:
http://msdn.microsoft.com/en-us/library/system.action.aspx
You’ve also got various generic versions of Action for methods that have parameters but have a void return type, and Func for methods that return something.
So your RunTheMethod method would look like
Then you can call it with: