Enum 操作
//如果需要计算,0开始没有意义,且数字都需要2进下只有一位为1其他为0者
//public enum Color1s { Red = 1, Green = 2, Blue = 4 }
//如果嫌麻烦可以用16进制的1,2,4,8在每位上重复即可,最多16位
public enum Color1s
{
Red = 0x001,
Green = 0x002,
Blue = 0x004,
Pink = 0x008,
Black = 0x010,
Brown = 0x020,
Yellow = 0x8000000000000000
}
//public enum Color1s { Red = 1, Green = 2, Blue = 4 }
//如果嫌麻烦可以用16进制的1,2,4,8在每位上重复即可,最多16位
public enum Color1s
{
Red = 0x001,
Green = 0x002,
Blue = 0x004,
Pink = 0x008,
Black = 0x010,
Brown = 0x020,
Yellow = 0x8000000000000000
}
1 Color1s color = Color1s.Blue | Color1s.Green;//增加
2 color = color &~Color1s.Blue;//减去CoLors1s.Blue
3 if ((color & Color1s.Green) == Color1s.Green)//判断是否存在
4 {
5
6 }
7
2 color = color &~Color1s.Blue;//减去CoLors1s.Blue
3 if ((color & Color1s.Green) == Color1s.Green)//判断是否存在
4 {
5
6 }
7
原因是因为位操作(先把数字转成2进制)
______________________________________________________________________
即0&0=0,0&1=0,1&0=0,1&1=1
00000011
& 00000101
00000001
即 0|0=0,0|1=1,1|0=1,1|1=1
| 00001111
00111111
即:0∧0=0,0∧1=1,1∧0=1, 1∧1=0
01111010
∧ 00001111
01110101
即~1 =0 ,~0=1
0000000000010101
~1111111111101010
H1
试验下