本文介绍了在C#中的对象和VAR的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
之间有什么区别对象和 VAR ?
推荐答案- 的 VAR - 不指定类型明确。让编译器弄明白该类型是什么。
- 类型是固定在设计时,不能参照其他类型的对象。
- 作为保利在评论中指出的那样,你会得到智能感知。
- 必须初始化。 VAR我; 将无法编译
- 不能用作方法的返回类型 。
- 必须是一个局部变量。不是字段或属性。
- 伟大工程具有的 匿名类型 。你得到智能感知。
- var - Not specifying the type explicitly. Letting compiler figure out what that type is.
- Type is fixed at design time and cannot refer to object of other type.
- As Pauli noted in a comment, you get intelliSense.
- Must be initialized. var i; won't compile.
- Cannot be used as return type of a method.
- Must be a local variable. Not a field or property.
- Works great with Anonymous Types. You get intelliSense.
- 可用于在运行时指任何类型的
- 在这里,你没有得到智能感知。
- Can be used to refer any type at runtime.
- Here you don't get intelliSense.
更多推荐
在C#中的对象和VAR的区别
发布评论