Gilad Naaman Gilad Naaman - 1 year ago 124
C# Question

Conditional XOR?

How come C# doesn't have a conditional



true xor false = true
true xor true = false
false xor false = false

Answer Source

In C#, conditional operators only execute their secondary operand if necessary.

Since an XOR must by definition test both values, a conditional version would be silly.


  • Logical AND: & - tests both sides every time.

  • Logical OR: | - test both sides every time.

  • Conditional AND: && - only tests the 2nd side if the 1st side is true.

  • Conditional OR: || - only test the 2nd side if the 1st side is false.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download