📅  最后修改于: 2022-03-11 14:49:23.582000             🧑  作者: Mango
//init
Dictionary> dictionaryStringListOfInt = new Dictionary>(){
{ "The First", new List(){ 1,2 } },
{ "The Second", new List(){ 1,2 } }
};
//add a dictinary Key Value pair with a new empty list
//note you can add an existing list but be carful as it is a ref type and only pointing to ints (changes will be seen in original list ref)
dictionaryStringListOfInt.Add("The New", new List());
//Add some values
dictionaryStringListOfInt["The New"].Add(1);
dictionaryStringListOfInt["The New"].Add(2);
//access some values via the Key and the values index
Console.WriteLine(dictionaryStringListOfInt["The New"][0]);//expected output 1
dictionaryStringListOfInt["The New"][0] = 3;
Console.WriteLine(dictionaryStringListOfInt["The New"][0]);//expected output 3
Console.WriteLine(dictionaryStringListOfInt["The New"][1]);//expected output 2