What is the ^= or ^ operator used for?

VitzzViperzz

Well-known member
Joined
Jan 16, 2017
Messages
75
Location
United Kingdom
Programming Experience
1-3
Hello,

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

C#:
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:
C#:
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.
 
Back
Top Bottom