Nicholas Paldino said:
In this case, I don't like it. It adds ambiguity to the code, in the
sense that you don't know what type you are working with (you have to know
the return type of the Open method on the File class, which is
unreasonable). For projections on anonymous types in queries for LINQ, it
definitely makes sense, but in cases where you know the type, I think it is
a bad practice.
In this particular case, I *might* agree - because it's not clear what
File.Open returns, although it's *fairly* obvious.
When you're using an object creation expression as the right hand side,
I like it a lot, particularly when the names get long:
var namesToPeople = new Map<string,Person>();
is clearer to me than
Map<string,Person> namesToPeople = new Map<string,Person>();
There's no ambiguity at all - you can tell that namesToPeople is
definitely going to be of type Map<string,Person> - but there's also no
redundancy, and less fluff to get in the way.
(It's particularly handy in listings for books, where horizontal space
is at a premium, but that's slightly different