The C# programming guide suggest using var when it enhances readability, for instance when the type is obvious, too complicated or not important at all.
The var keyword can also be useful
when the specific type of the variable
is tedious to type on the keyboard, or
is obvious, or does not add to the
readability of the code. One example
where var is helpful in this manner is
with nested generic types such as
those used with group operations. In
the following query, the type of the
query variable is
IEnumerable<IGrouping<string, Student>>
. As long as you and others
who must maintain your code understand
this, there is no problem with using
implicit typing for convenience and
brevity.
There is no general rule. There are situations where the explicit type may enhance readability.
Examples:
var x = new Thingy(); //type is obvious
var x = dict.Where(x => x.Value > 3); // type is complex and not important
Foo(GetValue(FromOverThere())); // type aren't implicit anyway
// equivalent to:
var fromOverThere = FromOverThere();
var value = GetValue(fromOverThere)
Foo(value);
FooDocument doc = repository.Get(id); // glad to see the type here.