我注意到c#中的全局变量还有其他线程.例如整数,字符串等.
public static int;
但是我需要使用另一个线程没有提及的“var”
public static var;
似乎不起作用.
所以我要问的是在c#中可以将“var”作为全局变量吗?
解决方法
C# specification(第26.1节)内容如下:
[`var is] an implicitly typed local variable declaration …
它更进一步:
A local variable declarator in an implicitly typed local variable
declaration is subject to the following restrictions:
- The declarator must include an initializer.
- The initializer must be an expression.
- The initializer expression must have a compile-time type which cannot
be the null type.- The local variable declaration cannot include
multiple declarators.- The initializer cannot refer to the declared variable itself
所以不,你不能这样做.此外,我建议不要考虑全局变量.