How to remove an item for a OR'd enum?

后端 未结 7 1745
后悔当初
后悔当初 2020-12-22 18:17

I have an enum like:

public enum Blah
{
    RED = 2,
    BLUE = 4,
    GREEN = 8,
    YELLOW = 16
}

Blah colors = Blah.RED | Blah.BLUE | Blah.YELLOW;
         


        
7条回答
  •  天命终不由人
    2020-12-22 18:59

    The other answers are correct, but to specifically remove blue from the above you would write:

    colors &= ~Blah.BLUE;
    

提交回复
热议问题