Indeed you can assign a power of 2 for values. In association with the flag attribute it gives good results.
Particularly when you want to print it using toString
. It's C# but you have nice informations here.
The power of 2 solution is really C/C++ oriented and is useful when it comes to be compatible with library written in such languages. It also provides a memory efficient format which is more friendly to database.
If you want to use a collection, a List will have double entries issues, you will prefer to use a HashSet instead. It will gives you facilities to add, remove or find tags in your combined enum without using magic boolean operations.
Also you should ask yourself : does a combined enum makes sense in my case ?
<FlagsAttribute>
Public Enum FileOption
Readable = 1
Writable = 2
End Enum
In this case, MyFileOption.Readable Or MyFileOption.Writable
makes sense. My file is readable and writable.
In one of my application I control an hardware that can send to the PC streams of data, I can choose which streams I want to be sent.
Public Enum HardwareStreams
StreamA
StreamB
Aux1
Aux2
End Enum
In this case HardwareStreams.StreamA Or HardwareStreams.Aux1
will not represents a hardware stream. But a set of such enum will makes sense.
Finally it depends on the usage of your enum and it's up to you.