title: Is there a way to toggle a boolean variable in C#?
body: <p>Is there a way to toggle the state of a Boolean variable in C#?</p>
  
  <p>I'm aware that this is a simple solution:</p>
  
  <pre><code>bool locked = false;
  
  if (locked == false)
  {
      locked = true;
  }
  else
  {
      locked = false;
  }
  </code></pre>
  
  <p>But can it be done in one line in something like this:</p>
  
  <pre><code>bool locked = false
  
  locked = locked.toggle();
  </code></pre>