HasFlag always returns True

前端 未结 5 646
有刺的猬
有刺的猬 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:21

    You can do bitwise operation like this:

    var alive = TestEnum.Alive;
    var hurt = TestEnum.Hurt;
    var aliveAndHurt = alive & hurt;
    

提交回复
热议问题