[C#]variable = !variable expression
Today we saw a new expression. Others may already know, but it's not the way I usually use it, so I'm writing it down with an explanation as follows.
[C# Code]
bool running = false;
running = !running;
The C# code running = !running; uses the logical NOT operator ! to toggle the value of a boolean variable called running.
When the code is executed, the current value of running is negated using the ! operator, which means that if running is currently true, it will be set to false, and if it is currently false, it will be set to true.
The assignment operator = then assigns the new value of running to the variable. This code is commonly used to toggle a boolean flag on and off, for example, to start or stop a process or to enable or disable a feature.
댓글
댓글 쓰기