C# Static variables - scope and persistence

前端 未结 9 1022
一向
一向 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:51

    They persist "for the lifetime of the application domain in which your program resides" according to Microsoft Docs: Static Classes and Static Class Members (C# Programming Guide).

    See also:

    • Microsoft Docs: Application Domains

    • .NET API Browser: AppDomain Class

提交回复
热议问题