using System;
using System.Collections.Generic;
class Program {
static void Main() {
// *** before: ***
// the type was spelled out twice, and the longer it was the harder
// the line became to read
Dictionary<string, List<int>> scoresOld = new Dictionary<string,
List<int>>();
scoresOld["Ann"] = new List<int>();
scoresOld["Ann"].Add(5);
foreach (KeyValuePair<string, List<int>> pair in scoresOld)
Console.WriteLine(pair.Key + " " + pair.Value.Count);
// *** in version 3.0: ***
var scores = new Dictionary<string, List<int>>(); // taken from the
//right side
scores["Ann"] = new List<int>();
scores["Ann"].Add(5);
foreach (var pair in scores)
Console.WriteLine(pair.Key + " " + pair.Value.Count);
var count = 0; // int
var ratio = 1.5; // double
var name = "Bob"; // string
Console.WriteLine(count + " " + ratio + " " + name);
// var is not "any type": the type is fixed at the declaration and
// never changes afterwards
// count = "seven"; // would not compile
//var empty; // would not compile: nothing to deduce
//from
// var nothing = null; // and neither would this one
}
}