What is the point of the [Flags] attribute you can bit test without it?
+7
A:
The Flags attribute allows you to see a CSV(comma separated value) of your enumerated type when calling ToString()
For Example:
[Flags]
public Enum Permissions
{
None =0,
Read = 1,
Write =2,
Delete= 4
}
Permissions p = Permissions.Read | Permissions.Write;
p.ToString() //Prints out "Read, Write"
However you can still get the same thing if you remove the flags attribute and just do:
p.ToString("F") //Prints out "Read, Write"
And as John pointed out it also allows you convert a CSV back to Enum using Enum.Parse
cgreeno
2010-07-30 11:43:32
"CSV value"..WTF :)
codymanix
2010-07-30 11:52:14
+2
A:
It changes the behaviour of converting between strings and the enum values (Enum.Parse
and ToString
).
Jon Skeet
2010-07-30 11:43:51
@Jon Skeet - Offtopic, but I just noticed you are the first one to cross 200 000 reputation. Congrats:)
Petar Minchev
2010-07-30 11:51:16