IList和IList 之间有什么区别

.net中List定义表明它实现了各种接口。

 public class List : IList, ICollection, IEnumerable, IList, ICollection, IEnumerable 

什么改变接口有没有T带来IList即如果我的一个类实现IList而不是IList ,那么我可以将它用作我的自定义集合类吗?

List实现IListIList是为了使它可以在代码假定为IList任何地方使用。 这将使更容易转换到通用IList因为它更合适。 此外,如果您希望重用.net 1.1或更早版本的代码,即使您的类是在.net 2.0或更高版本的程序集中实现的,它也可以实现。

IList您只能将定义的(T)类型的对象放入,IList可以包含不同类型的对象

由于AdressInformation不是客户列表中的有效对象,因此下面的代码将无法编译

 IList customers = new List(); customers.Add(new Customer()); customers.Add(new AdressInformation()); 

此代码将编译但在运行时转换exception

 IList customers = new List(); customers.Add(new Customer()); customers.Add(new AdressInformation());