In class A, I have
internal void AFoo(string s, Method DoOtherThing)
{
if (something)
{
//do something
}
else
DoOtherThing();
}
Now I need to be able to pass DoOtherThing to AFoo(). My requirement is that DoOtherThing can have any signature with return type almost always void. Something like this from Class B,
void Foo()
{
new ClassA().AFoo("hi", BFoo);
}
void BFoo(//could be anything)
{
}
I know I can do this with Action or by implementing delegates (as seen in many other SO posts) but how could this be achieved if signature of the function in Class B is unknown??
You need to pass a
delegateinstance;Actionwould work fine:If
BFoois parameterless it will work as written in your example:If it needs parameters, you’ll need to supply them: