The problem is that when wanting to add a value of type int
the list really what you are doing is add a new entry to the dictionary, therefore you mark the error of the key duplicated in the dictionary, for add a value to the list, you must first find the key in the dictionary and then add the value to the list. Using Linq you can add values to the list in this way:
Dictionary<string, List<int>> dic = new Dictionary<string, List<int>>();
dic.Add("1", new List<int> { 1, 2, 3 });
dic.Add("2", new List<int> { 4, 5, 6 });
dic.Add("3", new List<int> { 7, 8, 9 });
dic.FirstOrDefault(t => t.Key == "1").Value.Add(10);
dic.FirstOrDefault(t => t.Key == "1").Value.Add(11);
dic.FirstOrDefault(t => t.Key == "1").Value.Add(12);
foreach(var item in dic){
Console.WriteLine("Llave string: " + item.Key);
foreach (var valuesList in item.Value)
{
Console.WriteLine("Valores en lista: " + valuesList.ToString());
}
}
Demo