是 VAR 键入等同于变在VB?当对象可以接受任何数据类型,是这两个之间的区别?
Is the var type an equivalent to Variant in VB? When object can accept any datatype, what is the difference between those two?
推荐答案在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 typedVAR是不会反对
您一定要阅读: C#3.0 - 瓦尔是不是对象
You should definitely read this : C# 3.0 - Var Isn't Object
更多推荐
VAR"&之间的差异QUOT;和"对象"在C#中
发布评论