ArrayList 继承自Ilist,IList 是 ICollection 接口的子代
Ilist和ICollections 都说是:是所有非泛型列表的基接口(msdn)但有一个例子:(MSDN)
System.Collections.ArrayList list = new System.Collections.ArrayList();
// Add an integer to the list.
list.Add(3);
// Add a string to the list. This will compile, but may cause an error later.
list.Add("It is raining in Redmond.");int t = 0;
// This causes an InvalidCastException to be returned.
foreach (int x in list)
{
t += x;
}
小弟不明白ArrayList是不是泛型的?请赐教!
Ilist和ICollections 都说是:是所有非泛型列表的基接口(msdn)但有一个例子:(MSDN)
System.Collections.ArrayList list = new System.Collections.ArrayList();
// Add an integer to the list.
list.Add(3);
// Add a string to the list. This will compile, but may cause an error later.
list.Add("It is raining in Redmond.");int t = 0;
// This causes an InvalidCastException to be returned.
foreach (int x in list)
{
t += x;
}
小弟不明白ArrayList是不是泛型的?请赐教!
解决方案 »
- Font newFont = Font.FromHdc()
- 求 算法?(同样的数字)
- 求MDI主窗体工具栏可分别控制子窗体的方法
- SerialPort Close 线程阻塞
- 怎么让按钮只产生一个窗体?
- 弹出窗体2来设置窗体1里面的属性的问题!
- 不使用数据库,如何往gridview中追加行
- 求高人指教关于TCP接收的问题,分不够另开帖给!!!
- 请问谁有C#调用存储过程的通用类??十分感谢并送100分
- 请教.net(c#)中如何实现图像压缩技术?比如上传大图片直接转换成一定比例的小图片?请高手指教
- tabControl默认显示是第一页,怎样才能让它在窗体加载后,显示第四页?
- 请教各位指点一下我如何改正?
只有接口才能继承接口
ArrayList<int> list=new ArrayList<int>
List<int> list1 = new List<int>();// No boxing, no casting:
list1.Add(3);// Compile-time error:
// list1.Add("It is raining in Redmond.");
这是MSDN上的源代码
我的总题出自这(MSDN2005)
我就是想知道Arraylist是不是可以声明成泛型,如果可以为什么有这句:IList是所有非泛型列表的基接口(msdn)
谢谢.
System.Collections.Generic.List<>才是