I want to convert this C ++ code to C #:
typedef struct consoleCommand_s
{
char* cmd ;
void (*function)() ;
} consoleCommand_t ;
static consoleCommand_t commands[] =
{
{"clientlist", &CG__Clientlist},
{"say", &CG_Say},
{"nick", &CG_Nick},
{"logout", &CG_Logout}
} ;
static void CG_Logout(void)
{
}
The closest I came is:
public class Class1
{
public delegate void fnCommand_t();
public class consoleCommand_t
{
public string strCommandName;
public fnCommand_t fnCommand;
public consoleCommand_t(string x, fnCommand_t y)
{
this.strCommandName = x;
this.fnCommand = y;
}
}
public static void Nick()
{
Console.WriteLine("Changing Nick");
}
public static void Logout()
{
Console.WriteLine("Logging out");
}
public consoleCommand_t[] commands = new consoleCommand_t[] {
new consoleCommand_t("Nick", Nick),
new consoleCommand_t("Logout", Logout)
};
}
Now I wanted to ask:
A) Why should Nick and Logout be static if everything else is not?
B) Is there a C-like way to initialize an array of commands, that is, without new ones?
source
share