HasFlag always returns True

前端 未结 5 688
有刺的猬
有刺的猬 2021-01-06 07:39

There is a way to check if I got a flag in a series of flag?

Example:

[Flags]
Enum TestEnum
{
  ALIVE, DEAD, ALMOSTDEAD, HURT, OTHERS

}
// check if          


        
5条回答
  •  情书的邮戳
    2021-01-06 08:16

    If you want to use this as FLAGS I believe your declaration is wrong. Check out this previous post. Because of the default incrementing, HasFlag won't work as you expect unless you set the values to powers of 2.

    What does the [Flags] Enum Attribute mean in C#?

提交回复
热议问题