为什么不链表(T)实现IList(T)接口? [英] Why doesn't LinkedList(T) implement the IList(T) interface?

查看:119
本文介绍了为什么不链表(T)实现IList(T)接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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).

这篇关于为什么不链表(T)实现IList(T)接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆