首页 新闻 赞助 找找看

SortedList的用法问题

0
悬赏园豆:10 [已解决问题] 解决于 2012-08-14 14:35
using System;
using System.Collections.Generic;

public class SiteList
{
       protected SortedList<int, string> sites;
       //其他成员函数
       public string this[int index]
       {
              get
              {
                    if(index>sites.Count)
                        return (string)null;
                    return (string)sites.GetByIndex(inex)
             }
        }
       //其他东西 
}

这里VS提示“找不到GetByIndex的定义”,但是如果把using 中的Generic去掉的话,原来的“找不到定义”消失,却又提示“非泛型 类型“System.Collections.SortedList”不能与类型实参一起使用”,难道带参数的SortedList不是继承不带参数的SortedList吗?

问题补充:

这个是在《C#揭秘》书里面的代码,自己实践的时候却出现这个问题,很让人头疼啊

飞鸟_Asuka的主页 飞鸟_Asuka | 菜鸟二级 | 园豆:209
提问于:2012-08-14 13:41
< >
分享
最佳答案
0

SortedList

SortedList<TKey, TValue>

这是两个类型,同时 SortedList<TKey, TValue> 同 SortedList之间没有任何关系。

收获园豆:10
Launcher | 高人七级 |园豆:45045 | 2012-08-14 13:46

难道是《C#揭秘》书上有错误么?

飞鸟_Asuka | 园豆:209 (菜鸟二级) | 2012-08-14 13:59

@飞鸟_Asuka: 你把书的截图贴出来,我不认为书中会有如此明显的错误。

Launcher | 园豆:45045 (高人七级) | 2012-08-14 14:06

@Launcher: 

我反复比对书上代码和我录入的代码,确认没有录入错误

飞鸟_Asuka | 园豆:209 (菜鸟二级) | 2012-08-14 14:15

@飞鸟_Asuka: 从你的截图来看确实有错误,你确定作者没有对 SortedList<TKey, TValue> 类型增加扩展方法 GetByIndex?

Launcher | 园豆:45045 (高人七级) | 2012-08-14 14:25

@Launcher: 没有。一开始我以为GetByIndex是自己定义的,后来发现并没有这个函数的定义。

飞鸟_Asuka | 园豆:209 (菜鸟二级) | 2012-08-14 14:28

@飞鸟_Asuka: 那就是他写错了。

Launcher | 园豆:45045 (高人七级) | 2012-08-14 14:32

@Launcher: 那么也只能这么认为了,不过只要能理解委托和事件的用法就可以了。非常感谢

飞鸟_Asuka | 园豆:209 (菜鸟二级) | 2012-08-14 14:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册