How do I perform the inverse of the bitwise OR ( |= ) operator in C#? Is there a NOR bitwise operator in C# that I can use?
Scenario:
I am inheriting a base class from the .NET framework. This class has an operation which is setting a flag.
Example: flags |= 0x200;
In my derived class, I want to omit this flag setting, as if the operation flags |= 0x200; had never happened.
Is there a way to achieve this?
You can AND (
&) with the inverse (~) of the value you want to remove:If you intention is to ensure that this flag is not set. If you want to undo a previous change to this flag, then as @Russell says, XOR may be what you’re after.