Combine multiple enums into master enum list

c#, combinations, enums

Solution

Not sure I understand precisely. But you can make a `List<>` of all the values like this:

var allColors = new List<Enum>();

allColors.AddRange(Enum.GetValues(typeof(PrimaryColors)).Cast<Enum>());
allColors.AddRange(Enum.GetValues(typeof(SecondaryColors)).Cast<Enum>());

Instead of `List<Enum>` you could also use `HashSet<Enum>`. In any case, because you assign a `PrimaryColor` or `SecondaryColor` to a class type (namely `System.Enum`), you get boxing, but that's just a technical detail (probably).

Problem

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.

Original source