How come C# doesn't have a conditional XOR operator?
Example:
true xor false = true
true xor true = false
false xor false = false
How come C# doesn't have a conditional XOR operator?
Example:
true xor false = true
true xor true = false
false xor false = false
There is no such thing as conditional (short-circuiting) XOR. Conditional operators are only meaningful when there's a way to definitively tell the final outcome from looking at only the first argument. XOR (and addition) always require two arguments, so there's no way to short-circuit after the first argument.
If you know A=true, then (A XOR B) = !B.
If you know A=false, then (A XOR B) = B.
In both cases, if you know A but not B, then you don't know enough to know (A XOR B). You must always learn the values of both A and B in order to calculate the answer. There is literally no use case where you can ever resolve the XOR without both values.
Keep in mind, XOR by definition has four cases:
false xor true = true
true xor false = true
true xor true = false
false xor false = false
Again, hopefully it's obvious from the above that knowing the first value is never enough to get the answer without also knowing the second value. However, in your question, you omitted the first case. If you instead wanted
false op true = false (or DontCare)
true op false = true
true op true = false
false op false = false
then you can indeed get that by a short-circuiting conditional operation:
A && !B
But that's not an XOR.
NOTE: I know XOR and XNOR are bitwise operations, but considering the thing we are questioning here...
Ain't this work as conditional (boolean) XOR?
bool Xor(bool a, bool b){ return a != b }
| a | b | x |
|---|---|---|
| False | False | False |
| False | True | True |
| True | False | True |
| True | True | False |
Also I believe you can loop though data, aggregate them to use more than two operator. and still get the same result as Bitwise of Nth operand in same conditional manner