Changing bool values to opposite of the initial value

后端 未结 7 736
天命终不由人
天命终不由人 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:55

    Yes, there is!

    threadAlive ^= true;
    

    (this is a C# joke, in the most general case it won't work in C/C++/Javascript (it could work in C/C++/Javascript depending on some conditions), but it's true! ^ is the xor operator)

提交回复
热议问题