C# Static variables – scope and persistence

They will persist for the duration of AppDomain. Changes done to static variable are visible across methods.

MSDN:

If a local variable is declared with the Static keyword, its lifetime is longer than the execution time of the procedure in which it is declared. If the procedure is inside a module, the static variable survives as long as your application continues running.

See following for more details:

  • C#6 Language Specification – Static Variables
  • C#6 Language Specification – Application Startup
  • MSDN: Static Variable
  • MSDN: Variable Lifetime

Leave a Comment