1

Possible Duplicate:
Enum Flags Attribute

I've seen in Windows Forms that when you use a control which contains Anchor, you can set several enums at the same time.

I was trying to do that, but I haven't accomplished yet:

enum Foo
{
    A,
    B,
    C
}

Foo foo = A | B;   // here just receive the last one

Is possible doing this?

Community
  • 1
  • 1
Darf Zon
  • 6,268
  • 20
  • 90
  • 149

2 Answers2

4

Use the Flags attribute.

Flags:

[Flags]
enum Days2
{
    None = 0x0,
    Sunday = 0x1,
    Monday = 0x2,
    Tuesday = 0x4,
    Wednesday = 0x8,
    Thursday = 0x10,
    Friday = 0x20,
    Saturday = 0x40
}
Scott M.
  • 7,313
  • 30
  • 39
1

Yes this is the Flags attribute.

[Flags]
enum Foo 
{ 
  A = 1, 
  B = 2, 
  C = 4 
}


var foo = Foo.A | Foo.B;

More information here: What does the [Flags] Enum Attribute mean in C#?

Community
  • 1
  • 1
RvdK
  • 19,580
  • 4
  • 64
  • 107