为什么我要使用,而不是一个类型的变种? [英] Why should I use var instead of a type?

查看:134
本文介绍了为什么我要使用,而不是一个类型的变种?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
   ReSharper的和VAR

在我安装了整形它要求(通过警告),我用VAR只要有可能,例如:

After I have installed ReShaper it demands(by warnings) that I use var whenever possible, for example

UnhandledExceptionEventArgs ue = (UnhandledExceptionEventArgs) t;

ReSharper的希望把它变成

ReSharper wants to turn it into

var ue = (UnhandledExceptionEventArgs) t;

我喜欢的第一个版本好,是没有任何理由preFER变种?更好的性能?什么?或者是它只是一个code风格呢?

I like the first version better, is there any reason to prefer var? better performance? anything? or is it just a code style?

推荐答案

这真的只是一个编码风格。编译器生成完全相同的两个变种。

It's really just a coding style. The compiler generates the exact same for both variants.

另请参见这里的性能问题:

See also here for the performance question:

这篇关于为什么我要使用,而不是一个类型的变种?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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