VAR"&之间的差异QUOT;和"对象"在C#中 [英] Difference between "var" and "object" in C#
问题描述
是 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 typed
VAR是不会反对
您一定要阅读: C#3.0 - 瓦尔是不是对象
You should definitely read this : C# 3.0 - Var Isn't Object
这篇关于VAR"&之间的差异QUOT;和"对象"在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!