title: C# Static variables - scope and persistence
body: <p>I just did a little experiment:</p>
  
  <pre><code>public abstract class MyClass
  {
    private static int myInt = 0;
  
    public static int Foo()
    {
      return myInt;
    }
  
    public static int Foo(int n)
    {
      myInt = n;
      return bar();
    }
  
    private static int bar()
    {
      return myInt;
    }
  }
  </code></pre>
  
  <p>and then I ran:</p>
  
  <pre><code>MessageBox.Show(MyClass.Foo().ToString());
  MessageBox.Show(MyClass.Foo(3).ToString());
  MessageBox.Show(MyClass.Foo().ToString());
  MessageBox.Show(MyClass.Foo(10).ToString());
  MessageBox.Show(MyClass.Foo().ToString());
  </code></pre>
  
  <p>The results I expected were 0, 3, 0, 10, 0.</p>
  
  <p>To my surprise, I got 0, 3, 3, 10, 10.</p>
  
  <p>How long do these changes persist for? The duration of the program execution? The duration of the function calling the static method?</p>