using System;
using System.Collections.Generic;
class Program {
static void Main() {
// *** было: ***
// тип записывали дважды, и чем он длиннее, тем труднее
// читалась строка
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);
// *** в версии 3.0: ***
var scores = new Dictionary<string, List<int>>(); // берётся из правой
// части
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 - не "any type": тип фиксируется при объявлении
// и потом не меняется
// count = "seven"; // would not compile
// var empty; // не скомпилируется: нечего выводить
// var nothing = null; // и это тоже
}
}