为什么我要使用,而不是一个类型的变种?是一个、我要、而不、变种

2023-09-02 11:56:05 作者:馨兒

可能重复:    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:

C#变种VS特定类型的性能
 
精彩推荐