Is there a way to toggle the state of a Boolean variable in C#?
I'm aware that this is a simple solution:
bool locked = false;
if (locked == false)
{
locked = true;
}
else
{
locked = false;
}
But can it be done in one line in something like this:
bool locked = false
locked = locked.toggle();
Yes. Use the following:
locked = !locked;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With