Is there a way to toggle a boolean variable in C#?
You can define an extension method like this:
public static class Helpers
{
public static bool Toggle(this bool value)
{
return !value;
}
}
So that you can write something more meaningful like locked = locked.Toggle()
Hope it helps
You could also do:
locked ^= true;
Yes. Use the following:
locked = !locked;