我想你应该先决定需要哪种字典
- 要么将
string
映射到 List<Tuple<string,int>>
- 要么将
string
映射到 Tuple<string,int>
通过这行代码
dict_Info_A.Add("A", new Tuple<string,int>("hello", 1));
您正在尝试使用 Dictionary<string, Tuple<string, int>>
这样的字典应该像这样初始化:
var dict_Info_A = new Dictionary<string, Tuple<string, int>>();
这是您在原问题中展示的字典:
使用
var关键字初始化字典:
//you can also omit explicit dictionary declaration and use var instead
var dict_Info_A = new Dictionary<string, List<Tuple<string, int>>>();
初始化字典元素:
dict_Info_A["0"] = new List<Tuple<string, int>>();
将字典中的元素添加到列表中:
dict_Info_A["0"].Add(new Tuple<string, int>("asd", 1));