为什么我应该使用var而不是类型? [英] Why should I use var instead of a type?
本文介绍了为什么我应该使用var而不是类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
ReSharper和var
安装ReShaper之后,我使用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;
我更喜欢第一个版本,有什么理由喜欢 var ?更好的性能?什么?或者它只是一个代码风格?
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:
- C# 'var' vs specific type performance
这篇关于为什么我应该使用var而不是类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文