How do I pass a method as an argument? I do this all the time in Javascript and need to use anonymous methods to pass params. How do I do it in c#?
protecte
protected String ParamMethod(String sWho)
{
return "Hello " + sWho;
}
protected void RunMethod(Func ArgMethod)
{
MessageBox.Show(ArgMethod());
}
protected void MyMethod()
{
RunMethod( () => ParamMethod("World"));
}
That () =>
is important. It creates an anonymous Func
from the Func
that is ParamMethod.