Easiest way to flip a boolean value?

前端 未结 13 1444
后悔当初
后悔当初 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:36

    Just because I like to question code. I propose that you can also make use of the ternary by doing something like this:

    Example:

    bool flipValue = false;
    bool bShouldFlip = true;
    flipValue = bShouldFlip ? !flipValue : flipValue;
    
    0 讨论(0)
提交回复
热议问题