We have a class Command which takes an Action as a parameter in the constructor and we need to access some of the methods of the class Command from that Action. Is there a way how to achieve this?
public class Command
{
private readonly Action _action;
public Command(Action action)
{
_action = action;
}
public void Execute()
{
_action();
}
public void AnotherMethod()
{
}
}
static void Main()
{
var command = new Command(() =>
{
// do something
// ?? how to access and call
// command.AnotherMethod(); ??
// do something else
});
....
}
1 Answer