I found an example showing that a dictionary can be initialised as follows:
Dictionary<string, int> d = new Dictionary<string, int>()
{
{"cat", 2},
{"dog", 1},
{"llama", 0},
{"iguana", -1}
};
I don't understand how the syntax {"cat", 2}
is valid for creating a Key-Value Pair. Collection initialisation syntax seems to be of the form new MyObjType(){}
, while anonymous objects are of the form {a="a", b="b"}
. What is actually happening here?