C# Static variables - scope and persistence

前端 未结 9 1035
一向
一向 2020-11-27 05:38

I just did a little experiment:

public abstract class MyClass
{
  private static int myInt = 0;

  public static int Foo()
  {
    return myInt;
  }

  publi         


        
9条回答
  •  醉酒成梦
    2020-11-27 05:46

    Per the C# spec, a static variable will be initialized no later than the first time a class is loaded into an AppDomain, and will exist until that AppDomain is unloaded - usually when the program terminates.

提交回复
热议问题