I'm having a few issues in using a Flag enumeration.
My enumeration is the following (I declared the Flags attribute):
[Flags]
public enum Categ
{
None = 0,
Doors = 1,
Views = 2,
Rooms = 3,
Spaces = 4
}
But when I try to use it in my code it seems that instead of appending the last value it replaces the first one:
var category = Categ.Doors | Categ.Rooms;
//category is always equal to Rooms only
What am I doing wrong? I'm new to Flags so maybe I'm skipping some step. Thank you very much!
Adding the [Flags] attribute doesn't really do anything to the enum other than affect how .ToString() works. You still need to use values that are powers of 2 for each elements:
[Flags]
public enum Categ
{
None = 0,
Doors = 1,
Views = 2,
Rooms = 4,
Spaces = 8
// then 16, 32, 64 etc.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With