What is the point of the [Flags] attribute you can bit test without it?
2 Answers
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
Comments
It changes the behaviour of converting between strings and the enum values (Enum.Parse and ToString).
1 Comment
Petar Minchev
Offtopic, but I just noticed you are the first one to cross 200 000 reputation. Congrats:)