Let’s say I have an enum:
enum EnumDemo{
A1,
A2,
A3,
B1,
B2,
B3,
C1,
C2,
C3
}
What approach should I use to create enumset that can contain several EnumDemo elements,but all of the should be from one group, e.g.:
{A1, B2, C1}, {B1, C2}, but not {A1, A3, B1, C1}
Any thoughts are appreciated 🙂
You can keep in each enum element id of a group it belongs to. And create groups of enum based on this id:
This approach is good if groups are static and don’t change over time. Also you can create enum like
Groupand use it instead of int for id. Also you can changegroupIdof elements dynamically in your app but I’m not sure it’s good approach.