VAR"&之间的差异QUOT;和"对象"在C#中 [英] Difference between "var" and "object" in C#

查看:165
本文介绍了VAR"&之间的差异QUOT;和"对象"在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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆