The most likely time you'll need this is for anonymous types (where it is 100% required); but it also avoids repetition for the trivial cases, and IMO makes the line clearer. I don't need to see the type twice for a simple initialization.
For example:
Dictionary>> data = new Dictionary>>();
(please don't edit the hscroll in the above - it kinda proves the point!!!)
vs:
var data = new Dictionary>>();
There are, however, occasions when this is misleading, and can potentially cause bugs. Be careful using var
if the original variable and initialized type weren't identical. For example:
static void DoSomething(IFoo foo) {Console.WriteLine("working happily") }
static void DoSomething(Foo foo) {Console.WriteLine("formatting hard disk...");}
// this working code...
IFoo oldCode = new Foo();
DoSomething(oldCode);
// ...is **very** different to this code
var newCode = new Foo();
DoSomething(newCode);