Yes, this is a real exception. By default, enumerations are assigned values from 0 to, each one higher than the previous value, regardless of any FlagsAttribute s. (Of course, more complex rules when specifying some values manually - see MSDN docs )
Although it makes some sense that the flag enumeration automatically gets values in powers of two, I see reasons why it is probably better not to do this:
It is perfectly reasonable to have an enumeration like this:
[Flags] enum Foo { None, Bar, Baz, BarAndBaz }
This, of course, requires that the values be 0, 1, 2, and 3.
It would be pretty counter-intuitive for the presence of a simple attribute to change the whole meaning of a piece of C # code. Consider my Foo example. Should deleting the Flags attribute allow breaking the code by silently changing the counter values?
source share