First of all, I'm sorry if it's a duplicate. I don't know the right words to describe my problem.
Is it possible to change
the method
of an object to another method in another class
like this?
public Class Controller
{
void DoAction()
{ // Do something here }
}
public Class TheCaller
{
Controller c = new Controller();
TheCaller()
{
c.DoAction = AnotherAction; // Replace it with another method
}
void AnotherAction()
{ // Do something else here }
}
The closest I get was using Delegate
, but Delegate only accept static functions
.
Can someone help?