What is the ^= or ^ operator used for?


Well-known member
Jan 16, 2017
United Kingdom
Programming Experience

Just followed a book and it led me to a bit of code that was like:

Console.WriteLine($"Exactly one of the above is true? {isLessThan10 ^ isBetween0And5}");

Not going to go into the detail of the console output, but what does this actually do? There seems to be 30 words on MSDN and not much detail on any website. Can someone explain this please? I can see that it is a bitwise operator but what does it do?

Thanks for reading.
And here are the words from MSDN:
Binary ^ operators are predefined for the integral types and bool. For integral types, ^ computes the bitwise exclusive-OR of its operands. For bool operands, ^ computes the logical exclusive-or of its operands; that is, the result is true if and only if exactly one of its operands is true.
I'm not really sure what's not clear about that but, if it is, MSDN has examples too. Did you read this page? I'm not sure where the code you posted came from but the clue as to what the operator does is in it:
Console.WriteLine($"[B][U]Exactly one of the above is true[/U][/B]? {isLessThan10 ^ isBetween0And5}");
The Boolean expression will evaluate to True if exactly one of the two conditions (not neither and not both) is True.
Top Bottom