Stolen from the post on this issue at CodingHorror:
Unfortunately, you and everyone else pretty much got it wrong. While I agree with you that redundancy is not a good thing, the better way to solve this issue would have been to do something like the following:
MyObject m = new();
Or if you are passing parameters:
Person p = new(“FirstName”, “LastName);
Where in the creation of a new object, the compiler infers the type from the left-hand side, and not the right. This has other advantages over “var”, in that it could be used in field declarations as well (there are also some other areas that it could be useful as well, but I won’t get into it here).
In the end, it just wasn’t intended to reduce redundancy. Don’t get me wrong, “var” is VERY important in C# for anonymous types/projections, but the use here is just WAY off (and I’ve been saying this for a long, long time) as you obfuscate the type that is being used. Having to type it twice is too often, but declaring it zero times is too few.
Nicholas Paldino .NET/C# MVP on June 20, 2008 08:00 AM
I guess if your main concern is to have to type less — then there isn’t any argument that’s going to sway you from using it.
If you are only going to ever be the person who looks at your code, then who cares? Otherwise, in a case like this:
var people = Managers.People
it’s fine, but in a case like this:
var fc = Factory.Run();
it short circuits any immediate type deductions my brain could begin forming from the ‘English’ of the code.
Otherwise, just use your best judgment and programming ‘courtesy’ towards others who might have to work on your project.