首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法创建具有其他SortedList的SortedList

无法创建具有其他SortedList的SortedList
EN

Stack Overflow用户
提问于 2012-05-05 17:51:01
回答 2查看 110关注 0票数 0
代码语言:javascript
复制
SortedList<int, string> months = new SortedList<int, string>();
SortedList<int, SortedList> all = new SortedList<int, SortedList>();

我想创建一个SortedList,它包含另一个排序的'months‘类型列表,如上面的代码片段所示。

代码语言:javascript
复制
months.Add(1, "January");
all.Add(2012,months);

我得到了错误

无法从'System.Collections.Generic.SortedList‘转换为'System.Collections.SortedList’

我很困惑..。

EN

回答 2

Stack Overflow用户

发布于 2012-05-05 17:53:15

您忘记了为内部SortedList指定类型参数,它发现了一个非泛型参数,这是一个不同的类型。执行以下操作:

代码语言:javascript
复制
var all = new SortedList<int, SortedList<int, string>>();
票数 3
EN

Stack Overflow用户

发布于 2012-05-05 17:54:28

你必须给你的参数命名(否则它是一个不同的类型)。试试这个:

代码语言:javascript
复制
SortedList<int, SortedList<int, string> > all = new SortedList<int, SortedList<int, string> >(); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10460684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档