I\'m a little bit puzzled by the removal of enum flags to be perfectly honest.
Let me make an example, let\'s say we have an enum that looks like this
[F
Yes, the problem with the XOR operator is that unless you know that you've got all the rest of the flags, it will just flip them. So your XOR operation isn't "remove all but C" - it's "toggle the values of A and B". (So if the input was "A,C" you'd end up with "B,C", for example.)
&
is used because it's masking. The basic idea is that you get a value which contains just the bits you want, and then a bitwise AND of that value with your input value masks it.
To remove one specific flag (rather than retaining that specific flag), you'd typically use the ~
operator to create a mask of "all but that flag". For example:
var mask = ~Letter.A;
var newValue = originalValue & mask; // All previous values other than A