Is it possible to combine multiple enums together? Below is code sample of what I would like to see:
enum PrimaryColors
{
Red,
Yellow,
Blue
}
enum SecondaryColors
{
Orange,
Green,
Purple
}
//Combine them into a new enum somehow to result in:
enum AllColors
{
Red,
Orange,
Yellow,
Green,
Blue,
Purple
}
It does not matter what order they are, or what their backing numbers are, I just want to be able to combine them.
For context, this is so that multiple classes for a program I am working on would have enums associated with what they do. My main program would read all of the enums available from each of the support classes and make a master list of available enums of available commands (the the enums are for).
Edit: The reason for these enums is because my main program is reading in a list of commands to perform at certain times, and so I want to read in the file, see if the command in it is associated with one of my enums, and if it is, put it into a list of commands to perform.
enum
is fundamentally a compile-time concept. Are you looking to produce a C# file that contains a definition of something similar toAllColors
, or are you trying to do something else? – AndersonAllColors
programmatically, I mean, not create it until your application is running? If you just want to add them into a list, remember that all enums haveSystem.Object
andSystem.Enum
as their base classes. You could create some list based on one of those classes. Your enum values would be boxed, of course, but that's probably not a problem. – Syllogismenums
? – Clastic