数据集合小结

范型集合

 

类型

增加项

删除项

查找项

长度限制

是否可拷贝

Array

O(n)*

O(n)*

O(n)

List<T>

O(n)*

O(n)

O(n)

LinkedList<T>

O(1)

O(1)

O(n)

SortedList<TKey, TValue>

O(n)

O(n)

O(log n)

Keys:否

Values:是

Stack<T>

O(1)

O(1)

O(n)

Queue<T>

O(1)

O(1)

O(n)

HashSet<T>

O(1)

O(1)

O(1)

SortedSet<T>

O(1)

O(1)

O(1)

Dictionary<TKey, TValue>

O(1)

O(1)

O(1)

Keys:否

Values:是

SortedDictionary<TKey, TValue>

O(log n)

O(log n)

O(log n)

Keys:否

Values:是

 

非泛型集合

集合类型

描述

ArrayList

与List<object>相似

BitArray

布尔类型的位值数组,可执行布尔逻辑运算。

BitVector32

与BitArray相似,限制在32位。

ListDictionary

使用单链接列表实现IDictionary,与list使用相似。专为非常小的集合设计(元素数量是10或小于10),复杂度是O(n)。

HybridDictionary

在集合较小时,使用ListDictionary来实现IDictionary,然后当集合变大时,切换到Hashtable

StringCollection

与List<string>相同。

StringDictionary

与Dictionary<string, string>相同。

 

自定义的集合接口

接口

描述

方法

ICollection<T>

适用大部分集合类型的基本方法。继承了IEnumerable<T>接口。

Add, Clear, Contains, CopyTo, Remove

IEnumerable<T>

指定了集合中的元素可以使用foreach遍历

GetEnumerator

IDictionary<TKey, TValue>

可以通过键值对了访问集合中的元素,继承自ICollection<KeyValuePair<TKey, TValue>>接口

ContainsKey, TryGetValue

IList<T>

指定了集合可以通过索引访问,继承自ICollection<T>接口

IndexOf, Insert, RemoveAt

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值