无法创建具有另一个排序列表的排序列表
本文关键字:排序 列表 另一个 创建 | 更新日期: 2023-09-27 18:33:26
SortedList<int, string> months = new SortedList<int, string>();
SortedList<int, SortedList> all = new SortedList<int, SortedList>();
我想创建一个 SortedList,其中包含另一个"月"类型的排序列表,如上面的代码片段所示。
months.Add(1, "January");
all.Add(2012,months);
我收到错误
无法从"System.Collections.Generic.SortedList"转换为"System.Collections.SortedList"
我糊涂了...
你忘了为内部SortedList
指定类型参数,它找到了一个非泛型的,这是一个不同的类型。这样做:
var all = new SortedList<int, SortedList<int, string>>();
您必须命名参数(否则它是不同的类型)。试试这个:
SortedList<int, SortedList<int, string> > all = new SortedList<int, SortedList<int, string> >();