Search code examples
c#xor

XOR operation for two boolean field


Given two Boolean, how to come up with the most elegant one liner that computes the XOR operation in C#?

I know one can do this by a combination of switch or if else but that would make my code rather ugly.


Solution

  • bool xorValue = bool1 ^ bool2;