S
Stephen Martin
Works fine for me.
The out put is:
flag four is set
flag five is set
flag six is set
as expected.
The out put is:
flag four is set
flag five is set
flag six is set
as expected.
Mr.Tickle said:// Run this code and look for his obvious error by the compiler
Mr.Tickle said:WRONG, its a Flag, should be powers of 2. you ninney
Stephen Martin said:Works fine for me.
The out put is:
flag four is set
flag five is set
flag six is set
as expected.
Mr.Tickle said:// Run this code and look for his obvious error by the compiler
namespace FlagCheck
{
using System;
[Flags]
enum SomeFlags
{
None = 0,
One,
Two,
Three,
Four,
Five,
Six,
All = One | Two | Three | Four | Five | Six
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
SomeFlags f;
f = SomeFlags.Four; // Set flag FOUR and ONLY FOUR, get ready for a
supprise
if ( (f & SomeFlags.One) > 0)
{
Console.WriteLine("flag one is set");
}
if ( (f & SomeFlags.Two) > 0)
{
Console.WriteLine("flag two is set");
}
if ( (f & SomeFlags.Three) > 0)
{
Console.WriteLine("flag three is set");
}
if ( (f & SomeFlags.Four) > 0)
{
Console.WriteLine("flag four is set");
}
if ( (f & SomeFlags.Five) > 0)
{
Console.WriteLine("flag five is set");
}
if ( (f & SomeFlags.Six) > 0)
{
Console.WriteLine("flag six is set");
}
Console.ReadLine();
}
}
}
WRONG, its a Flag, should be powers of 2
Mr.Tickle said:They influence the operators , why not the enum default values.
So in a way they do MORPH it. fagot.ur a hoot.
Mr.Tickle said:Thats my point, it should be. There is no reason to have it otherwise.
Logic dictates that it should be powers of 2, nothing else.
Mr.Tickle said: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.
Alan Pretre said:Why don't you RTM and see what it does. Does it say that the FlagsAttribute
changes the way enum constants are defined? Hmmm? No it causes the
compiler to relax the restrictions on the bitwise OR operator, which would
otherwise not be allowed on the enum members.
Mr.Tickle said:I guess you are one of
those people that never actually made a DIFFERENCE; you are just a
FOLLOWER.Nuff said really.