How to maintain in an enum a list of enums
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?
Use the Flags attribute.
Flags:
[Flags]
enum Days2
{
None = 0x0,
Sunday = 0x1,
Monday = 0x2,
Tuesday = 0x4,
Wednesday = 0x8,
Thursday = 0x10,
Friday = 0x20,
Saturday = 0x40
}
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#?
链接地址: http://www.djcxy.com/p/54438.html上一篇: C#枚举,双前一个枚举值
下一篇: 如何在枚举中保留一个枚举列表