Easiest way to flip a boolean value?

前端 未结 13 1453
后悔当初
后悔当初 2020-12-04 08:31

I just want to flip a boolean based on what it already is. If it\'s true - make it false. If it\'s false - make it true.

Here is my code excerpt:

swi         


        
13条回答
  •  粉色の甜心
    2020-12-04 09:18

    Just because my favorite odd ball way to toggle a bool is not listed...

    bool x = true;
    x = x == false;
    

    works too. :)

    (yes the x = !x; is clearer and easier to read)

提交回复
热议问题