售船商
排序字典:SortedDictionary | ★★★★ |
---|
 | Dictionary的排序版 |
优势: | 短板: |
公告牌:排序字典(SortedDictionary)
-
需要对
字典类型数据结构 排序时,可选用。
操作指南
定义
System.Collections.类
-
SortedDictionary 泛型类是检索运算复杂度为 O(log n) 的二叉搜索树,
-
其中 n 是字典中的元素数。
就这点而言,它与 SortedList 泛型类相似。
memo
-
只要键用作 SortedDictionary 中的键,它们就必须是不可变的。SortedDictionary 中的每个键必须是唯一的。
键不能为 空引用,但是如果值类型 TValue 为引用类型,该值则可以为空。
属性
属性 | 说明 |
---|
Comparer | 获取用于对 IComparer 的元素进行排序的 SortedDictionary<TKey,TValue>。 |
Count | 获取包含在 SortedDictionary<TKey,TValue> 中的键/值对的数目。 |
Item[TKey | 获取或设置与指定的键关联的值。 |
Keys | 获得一个包含 SortedDictionary<TKey,TValue> 中的键的集合。 |
Values | 获得一个包含 SortedDictionary<TKey,TValue> 中的值的集合。 |
方法
命令 | 说明 |
---|
Add(TKey, TValue) | 将带有指定键和值的元素添加到 SortedDictionary<TKey,TValue> 中。 |
Clear() | 从 SortedDictionary<TKey,TValue> 中删除所有元素。 |
ContainsKey(TKey) | 确定是否 SortedDictionary<TKey,TValue> 包含带有指定键的元素。 |
ContainsValue(TValue) | 确定 SortedDictionary<TKey,TValue> 是否包含具有指定值的元素。 |
CopyTo(KeyValuePair<TKey,TValue>[], Int32) | 从指定的索引处开始,将 SortedDictionary<TKey,TValue> 的元素复制到指定的 KeyValuePair<TKey,TValue> 结构的数组中。 |
Equals(Object) | 确定指定的对象是否等于当前对象。(Inherited from Object) |
GetEnumerator() | 返回循环访问 SortedDictionary<TKey,TValue> 的枚举器。 |
GetHashCode() | 作为默认哈希函数。(Inherited from Object) |
GetType() | 获取当前实例的 Type。(Inherited from Object) |
MemberwiseClone() | 创建当前 Object 的浅表副本。(Inherited from Object) |
Remove(TKey) | 从 SortedDictionary<TKey,TValue> 中移除包含指定键的元素。 |
ToString() | 返回表示当前对象的字符串。(Inherited from Object) |
TryGetValue(TKey, TValue) | 获取与指定的键关联的值。 |
to Top
方法详解:动态更新
泰坦的肩膀
C# Dictionary和SortedDictionary的简介