Skip to main content
2 of 2
spelling, reference to official doc, changed text to "local variables" to elicit the reasoning and align it with official docs, correcting technical terminology of field/variable

C# doesn't support static local variables (that is, variables that are declared in method scope).

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members#static-members

You can declare static fields (class members) though.

Reasoning: Static field is a state, shared with all instances of particular type. Hence, the scope of the static field is entire type. That's why you can't declare static instance variable (within a method) - method is a scope itself, and items declared in a method must be inaccessible over the method's border.

Dennis
  • 37.9k
  • 11
  • 87
  • 158