XOR operation for two Boolean field

Graviton picture Graviton · Jul 6, 2010 · Viewed 28.9k times · Source

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.

Answer

Ronald Wildenberg picture Ronald Wildenberg · Jul 6, 2010
bool xorValue = bool1 ^ bool2;