Why does ReSharper want to use 'var' for everything? [duplicate]
What ReSharper suggests is clearly overuse of the var keyword. You can use it where the type is obvious:
var obj = new SomeObject();
If the type is not obvious, you should rather write it out:
SomeObject obj = DB.SomeClass.GetObject(42);
One reason is improved readability. Which is better?
Dictionary<int, MyLongNamedObject> dictionary = new Dictionary<int, MyLongNamedObject>();
or
var dictionary = new Dictionary<int, MyLongNamedObject>();
I personally prefer to turn this suggestion off. Using var
can often improve readability; but as you mentioned, it sometimes reduces it (with simple types, or when the resulting type is obscure).
I prefer to choose when I use var
and when I don't. But again, that's just me.