更新时间:2022-05-28 23:04:57
在Visual C#3.0开始,这是在方法范围内声明的变量可以有一个隐式类型 VAR
。一个隐式类型的局部变量是强类型的,就好像你已经自己声明的类型,但是编译器确定的类型。的下面的两个声明我
在功能上相当:
Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var
. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type. The following two declarations of i
are functionally equivalent:
var i = 10; //implicitly typed
int i = 10; //explicitly typed
VAR是不会反对
您一定要阅读: C#3.0 - 瓦尔是不是对象
You should definitely read this : C# 3.0 - Var Isn't Object