为什么ReSharper的想用“无功”的一切?想用、ReSharper

由网友(一心向你)分享简介:我刚刚开始使用ReSharper的使用Visual Studio(在许多建议后SO)。为了尝试一下我打开了一个最近的ASP.NET MVC项目。其中一个是暗示我注意到的第一个也是最频繁的事情之一就是,而不是改变大多数/所有的明确声明变种。例如:I've just started using ReSharper wit...

我刚刚开始使用ReSharper的使用Visual Studio(在许多建议后SO)。为了尝试一下我打开了一个最近的ASP.NET MVC项目。其中一个是暗示我注意到的第一个也是最频繁的事情之一就是,而不是改变大多数/所有的明确声明变种。例如:

I've just started using ReSharper with Visual Studio (after the many recommendations on SO). To try it out I opened up a recent ASP.NET MVC project. One of the first and most frequent things I've noticed it suggesting is to change most/all my explicit declarations to var instead. For example:

//From This:
MyObject foo = DB.MyObjects.SingleOrDefault(w => w.Id == 1);
//To This:
var foo = DB.MyObjects.SingleOrDefault(w => w.Id == 1);

等,即使是简单的类型,如 INT 布尔等。

这是为什么被推荐?我不来自计算机科学或.NET的背景下,具有陷入.NET开发最近,所以我真的很想知道发生了什么,以及是否是有益与否。

Why is this being recommended? I don't come from a computer science or .NET background, having "fallen into" .NET development recently, so I'd really like to understand what's going on and whether it's of benefit or not.

推荐答案

原因之一是提高可读性。哪个更好呢?

One reason is improved readability. Which is better?

Dictionary<int, MyLongNamedObject> dictionary = new Dictionary<int, MyLongNamedObject>();

var dictionary = new Dictionary<int, MyLongNamedObject>();