Do variables in static methods become static automatically because they are within static scopes in c#?

后端 未结 7 944
长情又很酷
长情又很酷 2021-01-17 17:29
public static void DoSomething()
{
int a;
string b;

//..do something
}

In the example above, i have declared two variables. Do they become static

相关标签:
7条回答
  • 2021-01-17 18:19

    Although available in C, static local variables are not supported in C#.

    If you want a local static variable equivalent, you can create an instance variable on the class, or a static variable. Otherwise, consider if the method itself belongs to the static class and whether it should be part of a different type.

    0 讨论(0)
提交回复
热议问题