title: C# static variables not persisting?
body: <p>Below is my code snippet, the variable "_lastError" doesn't seem to persist after it is set then accessed elsewhere. </p>
  
  <p>Can anyone give a heads up on what I missed or done incorrectly? I've debugged the program, setting a breakpoint at both the getter and the private setter. Nothing else seems to be accessing nor modifying the value of "_lastError" other than where it was intended to.</p>
  
  <pre><code>class Utils
  {
      private static string _lastError;
      public static string LastError
      {
          get
          {
              string lastError = Utils._lastError;
              Utils._lastError = string.Empty;
              return lastError;
          }
  
          private set
          {
              Utils._lastError = value;
          }
      }
  
      public static void Foo()
      {
          try { // .... // }
          catch (Exception ex)
          {
              Utils.LastError = ex.Message;
          }
      }
  }
  </code></pre>