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:
https://msdn.microsoft.com/en-us/library/6a71f45d.aspx

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: