Logical operators on enums
This question already has an answer here:
If you're going to use the enum as a bitmap like this, then the members need to be given values which use a different bit each:
[Flags]
enum MyEnum
{
Bold = 0x01,
Italic = 0x02,
Underlined = 0x04,
Struck = 0x08
}
By default, they've been given the numbers 0,1,2,3 - the first does nothing, and the second two overlap with the last.
As mentioned in the comments, you should also add the [Flags]
attribute to the enum definition, so that if you do ToString()
you get a properly formatted result (and so that everybody knows how you're using the enum) - if won't affect the way it works if you don't, though.
你正在使用按位运算符,这就是他们所做的
链接地址: http://www.djcxy.com/p/54430.html上一篇: 如何从[Flag]枚举属性中检索值?
下一篇: 逻辑运算符枚举