Say I have a function that takes an integer as an argument. I'd like to be able to use an enumerated list as a way to keep the integer values organized.
For example, I'd ideally like to be able to define these (pseudocode):
public enum days
{
monday,
tuesday,
etc...
}
public enum months
{
january,
february,
etc...
}
int doSomething(enum x)
{
return x + 1;
}
and then be able to call the function using either of the enumerated lists like this:
int a = doSomething(days.monday);
int y = doSomething(months.february);
This obviously won't work as-is because doSomething needs to be defined using just one of the enumerations (i.e. either days or months). I know of a couple of options. One is to simply cast to an int:
int a = doSomething((int)days.monday);
int y = doSomething((int)months.february);
The only problem with this is that this function gets called MANY places in my code, and it's clumsy to have to keep putting "(int)"s all over the place (one of the main motivations for grouping these int values together into enums in the first place is to make the code more readable).
Another option is to avoid enums altogether, and instead bundle the values into a container class, something like:
static class Days
{
static int x = 0;
static int monday = x++;
static int tuesday = x++;
}
Again, this will work but just seems awfully cumbersome when I have a lot of these container classes to define.
The answer might very well be that there is no simpler way, and that I need to be a grown-up and just accept one of these options. But I thought I would get a sanity check on that before committing to it. Is there a third option?