110,536
社区成员
发帖
与我相关
我的任务
分享
[Flags]
public enum SomeFlags
{
One = 1,
Two = 2,
Four = 4,
Eight = 8
}
static void Main(string[] args)
{
SomeFlags f = SomeFlags.Two | SomeFlags.Eight;
Console.WriteLine((int)f);
Console.WriteLine((f & SomeFlags.Two) == SomeFlags.Two); //true
Console.WriteLine((f & SomeFlags.Eight) == SomeFlags.Eight);//true
}
static void ShowBits(int number)
{
for (int i = 0; i < 32; i++)
{
int b = 1 << i;
if ((number & b) > 0) Console.WriteLine(b);
}
}