I have a bunch of strings in my resource(.resx) file. I am trying to directly use them as part of switch statement (see the sample code below).
class Test
{
static void main(string[] args)
{
string case = args[1];
switch(case)
{
case StringResources.CFG_PARAM1: // Do Something1
break;
case StringResources.CFG_PARAM2: // Do Something2
break;
case StringResources.CFG_PARAM3: // Do Something3
break;
default:
break;
}
}
}
I looked at some of the solutions, most of them seem to suggest that I need to declare them as const string
which I personally dislike.
I liked the top voted solution for this question: using collection of strings in a switch statement. But then I need to make sure that my enum
and strings
in resource file are tied together. I would like to know a neat way of doing that.
Edit:
Also found this great answer while researching how to use Action
: