有超过在C#中显式类型有什么优势利用VAR不? [英] What advantages does using var have over the explicit type in C#?

查看:189
本文介绍了有超过在C#中显式类型有什么优势利用VAR不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能显示的文件:结果
什么&rsquo的;?s var关键字的点结果
在C#中使用 var关键字的

Possible Duplicates:
What’s the point of the var keyword?
Use of var keyword in C#

我了解的IEnumerable< ...> 的数据类型可以使代码少一些可读或如何嵌套泛型似乎有点令人望而生畏。但是,除了代码的可读性,是否有使用无功而不是明确的类型的优势是什么?这似乎是通过明确的类型,你最好传达的变量是能够因为你知道它是什么。

I understand how IEnumerable<...> for a datatype can make the code a little less readable or how nested generics can seem a little daunting. But aside from code readability, are there advantages to using var instead of the explicit type? It seems like by using the explicit type, you'd better convey what the variable is capable of because you know what it is.

如果这是一个职场编码标准,我使用它的团队的缘故。在我自己的项目不过,我倾向于避免变种的用户。

If it's a workplace coding standard, I use it for the sake of teamwork. In my own projects however, I prefer to avoid the user of var.

推荐答案

var的要点是允许匿名类型,没有它,他们将是不可能的,这是它存在的原因。所有其他用途,我认为是懒惰的编码。

The point of var is to allow anonymous types, without it they would not be possible and that is the reason it exists. All other uses I consider to be lazy coding.

这篇关于有超过在C#中显式类型有什么优势利用VAR不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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