Bitfield enums and the Flags attribute
You can work with enum as bitfields if you use powers of 2 for the values.
For example, if you have an enum like this one:
enum Abcd {A = 1, B = 2, C = 4, D = 8}
you can use bitwise operations such as OR to combine values.
Maybe you noticed the Flags attribute which is part of the framework. But, what is its purpose, you may ask, since we can use enums as bitfields even if we do not add the Flags attribute. Well, this attribute is used for the ToString method for example. If you use the Flags attribute as follows:
[Flags]
enum Abcd {A = 1, B = 2, C = 4, D = 8}
then calling the ToString method on a variable of type Abcd containing A and C (myvar = Abcd.A | Abcd.C), the result will be "A, C". This is used by Visual Studio to display the value of bitfield properties, for example.
Conclusion, if you want to use bitfield enums, use the Flags attribute and powers of 2.
Note: VB.NET syntax:
<Flags()> _
Enum Abcd
A = 1
B = 2
C = 4
D = 8
End Enum