I'm creating a little command line interface for the player. They will be able to execute commands similar to in DOS.
The commands themselves are structs:
public struct Command {
public string name;
public string helpDoc;
} And the program has a list of commands:
List<Command> commands = new List<Command>(); I initialize all the commands like this:
commands.Add(new Command { name = "exit", helpDoc = "exits the OS" }); I also want to be able to pass in a function pointer when adding an element to the commands list.
Let's say I have a function like this:
public static void helpCommand() {
Console.Write("here is a list of commands: etc.");
} And I'd like use a delegate to bind this function to the command when I add the command to the commands list above.
What would the syntax for the struct's delegate member be? And how would I pass the delegate into the commands.Add line?
Not all command's functions will have the same signature.