Changing bool values to opposite of the initial value

后端 未结 7 701
天命终不由人
天命终不由人 2021-01-03 19:05

This maybe sound strange to you but I\'m too lazy to write everytime like

if (threadAlive)
{
            threadAlive = false;
}
        else
{
            th         


        
7条回答
  •  时光取名叫无心
    2021-01-03 19:40

    The logical negation operator ! is a unary operator that negates its operand. It is defined for bool and returns true if and only if its operand is false and false if and only if its operand is true:

    threadAlive = !threadAlive;
    

提交回复
热议问题