Initializer

Index Initializers

Use index initializers with dictionary. This elegantly prevents uninitialized dictionaries. See Object and Collection Initializers (C# Programming Guide).

var dict = new Dictionary<string, int>
{
    ["key1"] = 1,
    ["key2"] = 50,
};

Good example

var dict = new Dictionary<string, int>();
dict["key1"] = 1;
dict["key2"] = 50;

Not so good example

var dict = new Dictionary<string, int>
{
    { "key1", 1 },
    { "key2", 50 },
};

Deprecated way example