首页 新闻 会员 周边

关于IList接口和IList接口的问题~~~~~

0
悬赏园豆:10 [已解决问题] 解决于 2009-06-12 12:45

对不起大家,借用首页位置讨教一个问题,在CSDN上都没有满意的答案,只能求教于博客园中的各位高手了,闲话少说,上代码

 


 1 using System;
 2 using System.Collections.Generic;
 3 using System.Collections;
 4 using System.Text;
 5 
 6 namespace ConsoleApplication1
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             IList<object> testG = new List<object>();
13             IList test = new ArrayList();
14 
15             Console.WriteLine("testG is IList:{0}",(testG is IList));
16             Console.WriteLine("test is IList<object>:{0}", (test is IList<object>));
17             Console.WriteLine("test is IList<string>:{0}", (test is IList<string>));
18 
19             Console.Read();
20         }
21     }
22 }

 

 

这段代码的返回结果是:

testG is IList:True
test is IList <object>:False
test is IList <string>:False

查了一下MSDN,IList和IList<T>没有什么继承关系,但是这段代码的结果很出乎意料,请各位高手帮忙分析一下原因,谢谢~~~~~

LeonSun的主页 LeonSun | 初学一级 | 园豆:200
提问于:2009-06-12 11:27
< >
分享
最佳答案
0

答案出来了

winzheng | 大侠五级 |园豆:8797 | 2009-06-12 12:04
其他回答(1)
0

有什么问题吗?ArrayList作为非泛型集合类,实现了IList接口,但是这个类是.NET 1.0里面的,自然不会去实现泛型接口IList<T>,因此当然不可能作为IList<object>或IList<string>了

Gray Zhang | 园豆:17610 (专家六级) | 2009-06-12 12:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册