Reputation: 347
I want to create a class whose object takes some function in the constructor and can then produce it. What can I use for this?
This is for a class that will have the name of the command and the function it will perform. I want to create an object of this class to transfer to it a function that it will perform.
class Function
{
public Function() // here I want to pass the method that I want to execute
{
}
private void Execute()
{
//SomeMethod();
}
}
class Command
{
private string _name;
private Function SomeMethod;
public Command(string name)
{
_name = name;
}
}
Upvotes: 1
Views: 76
Reputation: 2776
something like this will do the trick for you. This shows the syntax to create a function that takes a function that takes a string and integer.
public void CallMeIWillCallYourFunction(Action<string,int> yourFunction)
{
yourFunction("HelloWorld", 123);
}
Upvotes: 4