Consider
[Flags] public enum State { IsCool = 0x1, SomethingElse = 0x2 }
I have a State someState
and if some expression evaluates to true, I want to unset the IsCool
flag of someState
regardless of it being already set or unset. This means that I can't really use someState ^= State.IsCool
but what can I use instead?
You need to approach this the reverse way than when setting a flag: bitwise AND the current state with the complement of the flag you want to remove.
someState &= ~State.IsCool;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With