为什么不链表(T)实现IList(T)接口?链表、接口、IList

由网友(别低头,皇冠会掉)分享简介:在C#中,LinkedList的(T)类没有实现IList(T)接口。不过,列表(T)类不实现IList(T)。为什么会出现这种差异?在功能上,它们是两个列表,所以这个设计选择似乎很奇怪。现在难以从列表(T)开关实现到链表(T)。In C#, the LinkedList(T) class does not impl...

在C#中,LinkedList的(T)类没有实现IList(T)接口。不过,列表(T)类不实现IList(T)。为什么会出现这种差异?在功能上,它们是两个列表,所以这个设计选择似乎很奇怪。现在难以从列表(T)开关实现到链表(T)。

In C#, the LinkedList(T) class does not implement the IList(T) interface. However, the List(T) class does implement IList(T). Why is there this discrepancy? Functionally, they are both lists, so this design choice seems odd. It now becomes difficult to switch implementations from List(T) to LinkedList(T).

推荐答案

的IList< T> 界面包含一个索引,索引是不是你希望在一个功能的LinkedList

IList<T> interface contains an indexer, the indexer is not a functionality you expect on a LinkedList.

名单,其中,T&GT; 可以保证访问的的 O(1)的的LinkedList 由它定义的是它的结构不能用来访问项目的 O(1)的。

List<T> can assure access to items in O(1), LinkedList by definition of it's it structure can't provide access to items in O(1).