16 December 2015

C# Operator ^= boolean flag toggle

Reviewing some code I spotted an interesting ^= operator that I had not seen before.

isBackgroundWindowOpen ^= true; // Toggles boolean flag.

C# Operators reference:

x ^= y – XOR assignment. XOR the value of y with the value of x, store the result in x, and return the new value.

No comments: