Re: Whats wrong with this C# compiler :D Can you guess the OBVIOUS mistake on Eric Gunnarsson's part.
"Mr.Tickle" <MrTickle@mrmen .com> wrote in message
news:%23bXMSEnk DHA.1808@TK2MSF TNGP09.phx.gbl. ..[color=blue]
> Sure you can override it if you want other values, just like normal
> behaviour today. but having an option to have it enumerate in powers of 2
> would be handy as in my example. Isnt that the point of Enums, to
> enumerate, in this case it enumerats incorrectly for bitfields on a base 2
> system.[/color]
The C# language spec says, in 14.3:
"...the associated value of the enum member is obtained by ___increasing
the associated value of the textually preceding enum member by one___. This
increased value must be within the range of values that can be represented
by the underlying type; otherwise, a compile-time error occurs. "
As Patrick says, various CLR languages may treat the attribute differently.
In my tests I couldn't see any difference in behavior with the
FlagsAttribute in C# (what I mean is whether present or not, C# seemed to
function the same.)
To return to your OP, I think the only one surprised was you.
-- Alan
"Mr.Tickle" <MrTickle@mrmen .com> wrote in message
news:%23bXMSEnk DHA.1808@TK2MSF TNGP09.phx.gbl. ..[color=blue]
> Sure you can override it if you want other values, just like normal
> behaviour today. but having an option to have it enumerate in powers of 2
> would be handy as in my example. Isnt that the point of Enums, to
> enumerate, in this case it enumerats incorrectly for bitfields on a base 2
> system.[/color]
The C# language spec says, in 14.3:
"...the associated value of the enum member is obtained by ___increasing
the associated value of the textually preceding enum member by one___. This
increased value must be within the range of values that can be represented
by the underlying type; otherwise, a compile-time error occurs. "
As Patrick says, various CLR languages may treat the attribute differently.
In my tests I couldn't see any difference in behavior with the
FlagsAttribute in C# (what I mean is whether present or not, C# seemed to
function the same.)
To return to your OP, I think the only one surprised was you.
-- Alan
Comment