Skip to main content
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
Source Link

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

C# haven't static variables at all.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 fieldfields in the particular type definition via C#(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 fieldinstance variable within(within a method) - method is a scope itself, and items declared in a method must be inaccessible over the method's border.

C# haven't static variables at all. You can declare static field in the particular type definition via C#. 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 field within a method - method is a scope itself, and items declared in a method must be inaccessible over the method's border.

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.

Source Link
Dennis
  • 37.9k
  • 11
  • 87
  • 158

C# haven't static variables at all. You can declare static field in the particular type definition via C#. 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 field within a method - method is a scope itself, and items declared in a method must be inaccessible over the method's border.