Im trying to find a solution for this problem. This is my example code:
class Program
{
private string Command;
private static string[] Commands = { "ComandOne", "CommandTwo", "CommandThree", "CommandFour" };
static void Main(string[] args)
{
Command = args[0];
switch(Command)
{
case Commands[0]: //do something
break;
case Commands[1]: //do something else
break;
case Commands[2]: //do something totally different
break;
case Commands[3]: //do something boring
break;
default: //do your default stuff
break;
}
}
void DifferentMethod()
{
foreach(string c in Commands)
{
//do something funny
}
}
}
This code doesn't work because the string values in the switch are not constants. I want to write easy maintainable code. I like to use something like an array because I need to use the same values somewhere else in a loop. With int-values an enum would be perfect, but I didn't find a small solution for the same thing with strings. I'm happy if anyone can point me to some article or even more if there is a short answer to my problem. Thanks in advance :)