SortedDictionary<TKey,TValue>类

表示根据键进行排序的键/值对的集合。

命名空间:                   System.Collections.Generic
程序集:         System(位于 System.dll)

继承层次结构

System.Object
System.Collections.Generic.SortedDictionary<TKey,TValue>

语法:

[SerializableAttribute]
public class SortedDictionary<TKey, TValue> : IDictionary<TKey,TValue>, 
ICollection<KeyValuePair<TKey,TValue>>, IEnumerable<KeyValuePair<TKey,TValue>>, 
IEnumerable, IDictionary, ICollection, IReadOnlyDictionary<TKey,TValue>, 
IReadOnlyCollection<KeyValuePair<TKey,TValue>>

类型参数
  • TKey

  • 字典中的键的类型。

  • TValue

  • 字典中的值的类型。

构造函数


名称说明
System_CAPS_pubmethodSortedDictionary<TKey,TValue>()

初始化 SortedDictionary<TKey,TValue> 类的一个新实例,该实例为空并对键类型使用默认 IComparer<T> 实现。

System_CAPS_pubmethodSortedDictionary<TKey,TValue>(IComparer<TKey>)

初始化 SortedDictionary<TKey,TValue> 类的一个新实例,该实例为空并对比较键使用指定 IComparer<T> 实现。

System_CAPS_pubmethodSortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>)

初始化 SortedDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IDictionary<TKey,TValue> 中复制的元素,并使用键类型的默认 IComparer<T> 实现。

System_CAPS_pubmethodSortedDictionary<TKey,TValue>(IDictionary<TKey,TValue>,IComparer<TKey>)

初始化 SortedDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IDictionary<TKey,TValue> 中复制的元素,并使用指定的 IComparer<T> 实现来比较键。

属性


名称说明
System_CAPS_pubpropertyComparer

获取用于对 IComparer<T> 的元素进行排序的 SortedDictionary<TKey,TValue>。

System_CAPS_pubpropertyCount

获取包含在 SortedDictionary<TKey,TValue> 中的键/值对的数目。

System_CAPS_pubpropertyItem[TKey]

获取或设置与指定的键关联的值。

System_CAPS_pubpropertyKeys

获得一个包含 SortedDictionary<TKey,TValue> 中的键的集合。

System_CAPS_pubpropertyValues

获得一个包含 SortedDictionary<TKey,TValue> 中的值的集合。

方法


名称说明
System_CAPS_pubmethodAdd(TKey,TValue)

将带有指定键和值的元素添加到 SortedDictionary<TKey,TValue> 中。

System_CAPS_pubmethodClear()

从 SortedDictionary<TKey,TValue> 中移除所有元素。

System_CAPS_pubmethodContainsKey(TKey)

确定是否 SortedDictionary<TKey,TValue> 包含带有指定键的元素。

System_CAPS_pubmethodContainsValue(TValue)

确定 SortedDictionary<TKey,TValue> 是否包含具有指定值的元素。

System_CAPS_pubmethodCopyTo(KeyValuePair<TKey,TValue>[],Int32)

从指定的索引处开始,将 SortedDictionary<TKey,TValue> 的元素复制到指定的 KeyValuePair<TKey,TValue> 结构的数组中。

System_CAPS_pubmethodEquals(Object)

确定指定的对象是否等于当前对象。(继承自 Object。)

System_CAPS_protmethodFinalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。(继承自 Object。)

System_CAPS_pubmethodGetEnumerator()

返回循环访问 SortedDictionary<TKey,TValue> 的枚举数。

System_CAPS_pubmethodGetHashCode()

作为默认哈希函数。(继承自 Object。)

System_CAPS_pubmethodGetType()

获取当前实例的 Type。(继承自 Object。)

System_CAPS_protmethodMemberwiseClone()

创建当前 Object 的浅表副本。(继承自 Object。)

System_CAPS_pubmethodRemove(TKey)

从 SortedDictionary<TKey,TValue> 中移除带有指定键的元素。

System_CAPS_pubmethodToString()

返回表示当前对象的字符串。(继承自 Object。)

System_CAPS_pubmethodTryGetValue(TKey,TValue)

获取与指定键关联的值。


显式接口实现


名称说明
System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>)

将某项添加到 ICollection<T> 中。

System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>)

确定是否 ICollection<T> 包含一个指定键和值。

System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>)

ICollection<T> 中移除指定元素的第一个匹配项。

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator()

返回循环访问集合的枚举数。

System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection.CopyTo(Array,Int32)

从特定的数组索引处开始,将 ICollection<T> 的元素复制到一个数组中。

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary.Add(Object,Object)

IDictionary 添加一个带有所提供的键和值的元素。

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary.Contains(Object)

确定是否 IDictionary 包含带有指定键的元素。

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary.GetEnumerator()

返回 IDictionaryEnumeratorIDictionary

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDictionary.Remove(Object)

IDictionary 中移除带有指定键的元素。

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

返回一个循环访问集合的枚举器。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection<KeyValuePair<TKey,TValue>>.IsReadOnly

获取一个值,该值指示 ICollection<T> 是否为只读。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary<TKey,TValue>.Keys

获取包含 ICollection<T> 的键的 IDictionary<TKey,TValue>

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary<TKey,TValue>.Values

获取一个 ICollection<T>,它包含 IDictionary<TKey,TValue> 中的值。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIReadOnlyDictionary<TKey,TValue>.Keys

获取包含在 SortedDictionary<TKey,TValue> 中的键的集合

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIReadOnlyDictionary<TKey,TValue>.Values

获取包含在 SortedDictionary<TKey,TValue> 中的值的集合

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.IsSynchronized

获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.SyncRoot

获取可用于同步对 ICollection 的访问的对象。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary.IsFixedSize

获取一个值,该值指示 IDictionary 是否具有固定大小。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary.IsReadOnly

获取一个值,该值指示 IDictionary 是否为只读。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary.Item[Object]

获取或设置具有指定键的元素。

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary.Keys

获取包含 ICollection 的键的 IDictionary

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDictionary.Values

获取一个 ICollection,它包含 IDictionary 中的值。

扩展方法


名称说明
System_CAPS_pubmethodAggregate<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,KeyValuePair<TKey,TValue>,KeyValuePair<TKey,TValue>>)

已重载。对一个序列应用累加器函数。(由 Enumerable 定义。)

System_CAPS_pubmethodAggregate<KeyValuePair<TKey,TValue>,TAccumulate>(TAccumulate,Func<TAccumulate,KeyValuePair<TKey,TValue>,TAccumulate>)

已重载。对一个序列应用累加器函数。 将指定的种子值用作累加器初始值。(由 Enumerable 定义。)

System_CAPS_pubmethodAggregate<KeyValuePair<TKey,TValue>,TAccumulate,TResult>(TAccumulate,Func<TAccumulate,KeyValuePair<TKey,TValue>,TAccumulate>,Func<TAccumulate,TResult>)

已重载。对一个序列应用累加器函数。 将指定的种子值用作累加器的初始值,并使用指定的函数选择结果值。(由 Enumerable 定义。)

System_CAPS_pubmethodAll<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

确定是否对序列中的所有元素都满足条件。(由 Enumerable 定义。)

System_CAPS_pubmethodAny<KeyValuePair<TKey,TValue>>()

已重载。确定序列是否包含任何元素。(由 Enumerable 定义。)

System_CAPS_pubmethodAny<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。  确定序列中是否存在元素满足条件。(由 Enumerable 定义。)

System_CAPS_pubmethodAsEnumerable<KeyValuePair<TKey,TValue>>()

返回输入类型化为 IEnumerable<T>。(由 Enumerable 定义。)

System_CAPS_pubmethodAsParallel()

已重载。启用查询的并行化。(由 ParallelEnumerable 定义。)

System_CAPS_pubmethodAsParallel<KeyValuePair<TKey,TValue>>()

已重载。启用查询的并行化。(由 ParallelEnumerable 定义。)

System_CAPS_pubmethodAsQueryable()

已重载。将转换 IEnumerableIQueryable。(由 Queryable 定义。)

System_CAPS_pubmethodAsQueryable<KeyValuePair<TKey,TValue>>()

已重载。将转换泛型 IEnumerable<T> 于泛型 IQueryable<T>。(由 Queryable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Decimal>)

已重载。计算序列的平均值 Decimal 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Double>)

已重载。计算序列的平均值 Double 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int32>)

已重载。计算序列的平均值 Int32 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int64>)

已重载。计算序列的平均值 Int64 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Decimal>>)

已重载。可以为 null 的序列的平均值,计算 Decimal 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Double>>)

已重载。可以为 null 的序列的平均值,计算 Double 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int32>>)

已重载。可以为 null 的序列的平均值,计算 Int32 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int64>>)

已重载。可以为 null 的序列的平均值,计算 Int64 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Single>>)

已重载。可以为 null 的序列的平均值,计算 Single 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodAverage<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Single>)

已重载。计算序列的平均值 Single 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodCast<TResult>()

将强制转换的元素 IEnumerable 为指定的类型。(由 Enumerable 定义。)

System_CAPS_pubmethodConcat<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>)

连接两个序列。(由 Enumerable 定义。)

System_CAPS_pubmethodContains<KeyValuePair<TKey,TValue>>(KeyValuePair<TKey,TValue>)

已重载。确定序列是否包含指定的元素使用的默认相等比较器。(由 Enumerable 定义。)

System_CAPS_pubmethodContains<KeyValuePair<TKey,TValue>>(KeyValuePair<TKey,TValue>,IEqualityComparer<KeyValuePair<TKey,TValue>>)

已重载。确定序列是否使用指定的包含指定的元素 IEqualityComparer<T>。(由 Enumerable 定义。)

System_CAPS_pubmethodCount<KeyValuePair<TKey,TValue>>()

已重载。返回序列中的元素数。(由 Enumerable 定义。)

System_CAPS_pubmethodCount<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回一个数字来表示多少个元素指定序列中的满足条件。(由 Enumerable 定义。)

System_CAPS_pubmethodDefaultIfEmpty<KeyValuePair<TKey,TValue>>()

已重载。返回单一实例集合中指定的序列或类型参数的默认值的元素,如果序列为空。(由 Enumerable 定义。)

System_CAPS_pubmethodDefaultIfEmpty<KeyValuePair<TKey,TValue>>(KeyValuePair<TKey,TValue>)

已重载。返回单一实例集合中指定的序列或指定的值的元素,如果序列为空。(由 Enumerable 定义。)

System_CAPS_pubmethodDistinct<KeyValuePair<TKey,TValue>>()

已重载。通过使用的默认相等比较器对值进行比较从序列返回非重复元素。(由 Enumerable 定义。)

System_CAPS_pubmethodDistinct<KeyValuePair<TKey,TValue>>(IEqualityComparer<KeyValuePair<TKey,TValue>>)

已重载。返回序列中通过使用指定的非重复元素 IEqualityComparer<T> 对值进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodElementAt<KeyValuePair<TKey,TValue>>(Int32)

返回序列中的指定索引处的元素。(由 Enumerable 定义。)

System_CAPS_pubmethodElementAtOrDefault<KeyValuePair<TKey,TValue>>(Int32)

返回序列中指定索引处的元素;如果索引超出范围,则返回默认值。(由 Enumerable 定义。)

System_CAPS_pubmethodExcept<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>)

已重载。通过使用默认的相等比较器对值进行比较,生成两个序列的差集。(由 Enumerable 定义。)

System_CAPS_pubmethodExcept<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>,IEqualityComparer<KeyValuePair<TKey,TValue>>)

已重载。使用指定的生成两个序列的差集 IEqualityComparer<T> 对值进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodFirst<KeyValuePair<TKey,TValue>>()

已重载。返回一个序列的第一个元素。(由 Enumerable 定义。)

System_CAPS_pubmethodFirst<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回序列中满足指定条件的第一个元素。(由 Enumerable 定义。)

System_CAPS_pubmethodFirstOrDefault<KeyValuePair<TKey,TValue>>()

已重载。返回序列中的第一个元素;如果序列中不包含任何元素,则返回默认值。(由 Enumerable 定义。)

System_CAPS_pubmethodFirstOrDefault<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回序列中满足条件的第一个元素;如果未找到这样的元素,则返回默认值。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>)

已重载。根据指定的键选择器函数对序列的元素进行分组。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>,IEqualityComparer<TKey>)

已重载。根据指定的键选择器函数并将进行比较的键使用指定的比较器对序列的元素进行分组。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey,TElement>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>)

已重载。根据指定的键选择器函数和项目的元素的每个组通过使用指定的函数对序列的元素进行分组。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey,TElement>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>,IEqualityComparer<TKey>)

已重载。根据键选择器函数对序列的元素进行分组。 通过使用比较器对键进行比较,并且通过使用指定的函数对每个组的元素进行投影。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey,TResult>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<TKey,IEnumerable<KeyValuePair<TKey,TValue>>,TResult>)

已重载。根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey,TResult>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<TKey,IEnumerable<KeyValuePair<TKey,TValue>>,TResult>,IEqualityComparer<TKey>)

已重载。根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。 通过使用指定的比较器对键进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey,TElement,TResult>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>,Func<TKey,IEnumerable<TElement>,TResult>)

已重载。根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。 通过使用指定的函数对每个组的元素进行投影。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupBy<KeyValuePair<TKey,TValue>,TKey,TElement,TResult>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>,Func<TKey,IEnumerable<TElement>,TResult>,IEqualityComparer<TKey>)

已重载。根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。 通过使用指定的比较器对键值进行比较,并且通过使用指定的函数对每个组的元素进行投影。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupJoin<KeyValuePair<TKey,TValue>,TInner,TKey,TResult>(IEnumerable<TInner>,Func<KeyValuePair<TKey,TValue>,TKey>,Func<TInner,TKey>,Func<KeyValuePair<TKey,TValue>,IEnumerable<TInner>,TResult>)

已重载。基于键相等对两个序列的元素进行关联,并对结果进行分组。 使用默认的相等比较器对键进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodGroupJoin<KeyValuePair<TKey,TValue>,TInner,TKey,TResult>(IEnumerable<TInner>,Func<KeyValuePair<TKey,TValue>,TKey>,Func<TInner,TKey>,Func<KeyValuePair<TKey,TValue>,IEnumerable<TInner>,TResult>,IEqualityComparer<TKey>)

已重载。基于键相等对两个序列的元素进行关联,并对结果进行分组。 指定 IEqualityComparer<T> 用来对键进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodIntersect<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>)

已重载。通过使用默认的相等比较器对值进行比较,生成两个序列的交集。(由 Enumerable 定义。)

System_CAPS_pubmethodIntersect<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>,IEqualityComparer<KeyValuePair<TKey,TValue>>)

已重载。使用指定的生成两个序列的交集 IEqualityComparer<T> 对值进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodJoin<KeyValuePair<TKey,TValue>,TInner,TKey,TResult>(IEnumerable<TInner>,Func<KeyValuePair<TKey,TValue>,TKey>,Func<TInner,TKey>,Func<KeyValuePair<TKey,TValue>,TInner,TResult>)

已重载。基于匹配键对两个序列的元素关联。 使用默认的相等比较器对键进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodJoin<KeyValuePair<TKey,TValue>,TInner,TKey,TResult>(IEnumerable<TInner>,Func<KeyValuePair<TKey,TValue>,TKey>,Func<TInner,TKey>,Func<KeyValuePair<TKey,TValue>,TInner,TResult>,IEqualityComparer<TKey>)

已重载。基于匹配键对两个序列的元素关联。 指定 IEqualityComparer<T> 用来对键进行比较。(由 Enumerable 定义。)

System_CAPS_pubmethodLast<KeyValuePair<TKey,TValue>>()

已重载。返回一个序列的最后一个元素。(由 Enumerable 定义。)

System_CAPS_pubmethodLast<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回序列中满足指定条件的最后一个元素。(由 Enumerable 定义。)

System_CAPS_pubmethodLastOrDefault<KeyValuePair<TKey,TValue>>()

已重载。返回序列中的最后一个元素;如果序列中不包含任何元素,则返回默认值。(由 Enumerable 定义。)

System_CAPS_pubmethodLastOrDefault<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回序列中满足条件的最后一个元素;如果未找到这样的元素,则返回默认值。(由 Enumerable 定义。)

System_CAPS_pubmethodLongCount<KeyValuePair<TKey,TValue>>()

已重载。返回 Int64 ,它表示序列中的元素的总数。(由 Enumerable 定义。)

System_CAPS_pubmethodLongCount<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回 Int64 表示序列中的多少个元素满足条件。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>()

已重载。泛型序列中返回的最大值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Decimal>)

已重载。调用转换函数对序列的每个元素并返回最大 Decimal 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Double>)

已重载。调用转换函数对序列的每个元素并返回最大 Double 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int32>)

已重载。调用转换函数对序列的每个元素并返回最大 Int32 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int64>)

已重载。调用转换函数对序列的每个元素并返回最大 Int64 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Decimal>>)

已重载。调用转换函数对序列的每个元素并返回最大可以为 null Decimal 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Double>>)

已重载。调用转换函数对序列的每个元素并返回最大可以为 null Double 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int32>>)

已重载。调用转换函数对序列的每个元素并返回最大可以为 null Int32 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int64>>)

已重载。调用转换函数对序列的每个元素并返回最大可以为 null Int64 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Single>>)

已重载。调用转换函数对序列的每个元素并返回最大可以为 null Single 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Single>)

已重载。调用转换函数对序列的每个元素并返回最大 Single 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMax<KeyValuePair<TKey,TValue>,TResult>(Func<KeyValuePair<TKey,TValue>,TResult>)

已重载。调用泛型序列的每个元素的转换函数并返回最大结果值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>()

已重载。泛型序列中返回的最小值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Decimal>)

已重载。调用转换函数对序列的每个元素,并返回所需的最低 Decimal 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Double>)

已重载。调用转换函数对序列的每个元素,并返回所需的最低 Double 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int32>)

已重载。调用转换函数对序列的每个元素,并返回所需的最低 Int32 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int64>)

已重载。调用转换函数对序列的每个元素,并返回所需的最低 Int64 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Decimal>>)

已重载。调用转换函数对序列的每个元素,并返回最小值可以为 null Decimal 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Double>>)

已重载。调用转换函数对序列的每个元素,并返回最小值可以为 null Double 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int32>>)

已重载。调用转换函数对序列的每个元素,并返回最小值可以为 null Int32 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int64>>)

已重载。调用转换函数对序列的每个元素,并返回最小值可以为 null Int64 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Single>>)

已重载。调用转换函数对序列的每个元素,并返回最小值可以为 null Single 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Single>)

已重载。调用转换函数对序列的每个元素,并返回所需的最低 Single 值。(由 Enumerable 定义。)

System_CAPS_pubmethodMin<KeyValuePair<TKey,TValue>,TResult>(Func<KeyValuePair<TKey,TValue>,TResult>)

已重载。调用泛型序列的每个元素的转换函数,并返回最小的结果值。(由 Enumerable 定义。)

System_CAPS_pubmethodOfType<TResult>()

筛选的元素 IEnumerable 根据指定的类型。(由 Enumerable 定义。)

System_CAPS_pubmethodOrderBy<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>)

已重载。按根据某个键按升序对序列的元素进行排序。(由 Enumerable 定义。)

System_CAPS_pubmethodOrderBy<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>,IComparer<TKey>)

已重载。按使用指定的比较器按升序对序列的元素进行排序。(由 Enumerable 定义。)

System_CAPS_pubmethodOrderByDescending<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>)

已重载。按根据某个键按降序对序列的元素进行排序。(由 Enumerable 定义。)

System_CAPS_pubmethodOrderByDescending<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>,IComparer<TKey>)

已重载。使用指定的比较器按降序对序列的元素排序。(由 Enumerable 定义。)

System_CAPS_pubmethodReverse<KeyValuePair<TKey,TValue>>()

反转序列中元素的顺序。(由 Enumerable 定义。)

System_CAPS_pubmethodSelect<KeyValuePair<TKey,TValue>,TResult>(Func<KeyValuePair<TKey,TValue>,TResult>)

已重载。将序列中的每个元素投影到新表单。(由 Enumerable 定义。)

System_CAPS_pubmethodSelect<KeyValuePair<TKey,TValue>,TResult>(Func<KeyValuePair<TKey,TValue>,Int32,TResult>)

已重载。通过合并元素的索引投影到一个新窗体的序列的每个元素。(由 Enumerable 定义。)

System_CAPS_pubmethodSelectMany<KeyValuePair<TKey,TValue>,TResult>(Func<KeyValuePair<TKey,TValue>,IEnumerable<TResult>>)

已重载。一个序列的每个元素投影 IEnumerable<T> 并将合并为一个序列将结果序列。(由 Enumerable 定义。)

System_CAPS_pubmethodSelectMany<KeyValuePair<TKey,TValue>,TResult>(Func<KeyValuePair<TKey,TValue>,Int32,IEnumerable<TResult>>)

已重载。一个序列的每个元素投影 IEnumerable<T>, ,并将合并为一个序列将结果序列。 每个源元素的索引用于该元素的投影表。(由 Enumerable 定义。)

System_CAPS_pubmethodSelectMany<KeyValuePair<TKey,TValue>,TCollection,TResult>(Func<KeyValuePair<TKey,TValue>,IEnumerable<TCollection>>,Func<KeyValuePair<TKey,TValue>,TCollection,TResult>)

已重载。一个序列的每个元素投影 IEnumerable<T>, 将平展为一个序列,将结果序列,其中调用结果选择器函数对每个元素。(由 Enumerable 定义。)

System_CAPS_pubmethodSelectMany<KeyValuePair<TKey,TValue>,TCollection,TResult>(Func<KeyValuePair<TKey,TValue>,Int32,IEnumerable<TCollection>>,Func<KeyValuePair<TKey,TValue>,TCollection,TResult>)

已重载。一个序列的每个元素投影 IEnumerable<T>, 将平展为一个序列,将结果序列,其中调用结果选择器函数对每个元素。 每个源元素的索引用于该元素的中间投影表。(由 Enumerable 定义。)

System_CAPS_pubmethodSequenceEqual<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>)

已重载。确定两个序列是否相等的元素进行比较通过使用相应类型的默认相等比较器。(由 Enumerable 定义。)

System_CAPS_pubmethodSequenceEqual<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>,IEqualityComparer<KeyValuePair<TKey,TValue>>)

已重载。确定两个序列是否通过使用指定的比较它们的元素相等 IEqualityComparer<T>。(由 Enumerable 定义。)

System_CAPS_pubmethodSingle<KeyValuePair<TKey,TValue>>()

已重载。返回序列的唯一元素;如果该序列并非恰好包含一个元素,则会引发异常。(由 Enumerable 定义。)

System_CAPS_pubmethodSingle<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回序列中满足指定条件的唯一元素;如果有多个这样的元素存在,则会引发异常。(由 Enumerable 定义。)

System_CAPS_pubmethodSingleOrDefault<KeyValuePair<TKey,TValue>>()

已重载。返回一个序列,或默认值的唯一元素,如果序列为空,则为如果序列中存在多个元素,则此方法将引发异常。(由 Enumerable 定义。)

System_CAPS_pubmethodSingleOrDefault<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回序列中满足指定条件的唯一元素;如果这类元素不存在,则返回默认值;如果有多个元素满足该条件,此方法将引发异常。(由 Enumerable 定义。)

System_CAPS_pubmethodSkip<KeyValuePair<TKey,TValue>>(Int32)

跳过指定的数量的序列中的元素,然后返回剩余元素。(由 Enumerable 定义。)

System_CAPS_pubmethodSkipWhile<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。只要指定的条件为 true,然后返回剩余元素,跳过序列中的元素。(由 Enumerable 定义。)

System_CAPS_pubmethodSkipWhile<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int32,Boolean>)

已重载。只要指定的条件为 true,然后返回剩余元素,跳过序列中的元素。 将在谓词函数的逻辑中使用元素的索引。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Decimal>)

已重载。计算的序列的和 Decimal 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Double>)

已重载。计算的序列的和 Double 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int32>)

已重载。计算的序列的和 Int32 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int64>)

已重载。计算的序列的和 Int64 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Decimal>>)

已重载。计算可以为 null 的序列的和 Decimal 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Double>>)

已重载。计算可以为 null 的序列的和 Double 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int32>>)

已重载。计算可以为 null 的序列的和 Int32 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Int64>>)

已重载。计算可以为 null 的序列的和 Int64 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Nullable<Single>>)

已重载。计算可以为 null 的序列的和 Single 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodSum<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Single>)

已重载。计算的序列的和 Single 通过调用对输入序列中的每个元素的转换函数获得的值。(由 Enumerable 定义。)

System_CAPS_pubmethodTake<KeyValuePair<TKey,TValue>>(Int32)

从序列的开头返回指定的数量的连续元素。(由 Enumerable 定义。)

System_CAPS_pubmethodTakeWhile<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。返回序列中的元素,只要指定的条件为真。(由 Enumerable 定义。)

System_CAPS_pubmethodTakeWhile<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int32,Boolean>)

已重载。返回序列中的元素,只要指定的条件为真。 将在谓词函数的逻辑中使用元素的索引。(由 Enumerable 定义。)

System_CAPS_pubmethodToArray<KeyValuePair<TKey,TValue>>()

创建一个数组,从 IEnumerable<T>。(由 Enumerable 定义。)

System_CAPS_pubmethodToDictionary<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>)

已重载。创建 Dictionary<TKey,TValue>IEnumerable<T> 根据指定的键选择器函数。(由 Enumerable 定义。)

System_CAPS_pubmethodToDictionary<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>,IEqualityComparer<TKey>)

已重载。创建 Dictionary<TKey,TValue>IEnumerable<T> 根据指定的键选择器函数和键比较器。(由 Enumerable 定义。)

System_CAPS_pubmethodToDictionary<KeyValuePair<TKey,TValue>,TKey,TElement>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>)

已重载。创建 Dictionary<TKey,TValue>IEnumerable<T> 根据指定的键选择器和元素选择器函数。(由 Enumerable 定义。)

System_CAPS_pubmethodToDictionary<KeyValuePair<TKey,TValue>,TKey,TElement>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>,IEqualityComparer<TKey>)

已重载。创建 Dictionary<TKey,TValue>IEnumerable<T> 根据指定的键选择器函数、 比较器和元素选择器函数。(由 Enumerable 定义。)

System_CAPS_pubmethodToList<KeyValuePair<TKey,TValue>>()

创建 List<T>IEnumerable<T>。(由 Enumerable 定义。)

System_CAPS_pubmethodToLookup<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>)

已重载。创建 Lookup<TKey,TElement>IEnumerable<T> 根据指定的键选择器函数。(由 Enumerable 定义。)

System_CAPS_pubmethodToLookup<KeyValuePair<TKey,TValue>,TKey>(Func<KeyValuePair<TKey,TValue>,TKey>,IEqualityComparer<TKey>)

已重载。创建 Lookup<TKey,TElement>IEnumerable<T> 根据指定的键选择器函数和键比较器。(由 Enumerable 定义。)

System_CAPS_pubmethodToLookup<KeyValuePair<TKey,TValue>,TKey,TElement>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>)

已重载。创建 Lookup<TKey,TElement>IEnumerable<T> 根据指定的键选择器和元素选择器函数。(由 Enumerable 定义。)

System_CAPS_pubmethodToLookup<KeyValuePair<TKey,TValue>,TKey,TElement>(Func<KeyValuePair<TKey,TValue>,TKey>,Func<KeyValuePair<TKey,TValue>,TElement>,IEqualityComparer<TKey>)

已重载。创建 Lookup<TKey,TElement>IEnumerable<T> 根据指定的键选择器函数、 比较和元素选择器函数。(由 Enumerable 定义。)

System_CAPS_pubmethodUnion<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>)

已重载。通过使用默认的相等比较器生成的两个序列的并集。(由 Enumerable 定义。)

System_CAPS_pubmethodUnion<KeyValuePair<TKey,TValue>>(IEnumerable<KeyValuePair<TKey,TValue>>,IEqualityComparer<KeyValuePair<TKey,TValue>>)

已重载。使用指定的生成两个序列的并集 IEqualityComparer<T>。(由 Enumerable 定义。)

System_CAPS_pubmethodWhere<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Boolean>)

已重载。基于谓词筛选值序列。(由 Enumerable 定义。)

System_CAPS_pubmethodWhere<KeyValuePair<TKey,TValue>>(Func<KeyValuePair<TKey,TValue>,Int32,Boolean>)

已重载。基于谓词筛选值序列。 将在谓词函数的逻辑中使用每个元素的索引。(由 Enumerable 定义。)

System_CAPS_pubmethodZip<KeyValuePair<TKey,TValue>,TSecond,TResult>(IEnumerable<TSecond>,Func<KeyValuePair<TKey,TValue>,TSecond,TResult>)

适用于两个序列,生成结果的序列的相应元素指定的函数。(由 Enumerable 定义。)


备注

 SortedDictionary<TKey,TValue> 泛型类是与 O(log n) 检索二进制搜索树其中 n 是在字典中的元素数目。 在这一方面,它是类似于 SortedList<TKey,TValue> 泛型类。 这两个类具有相似的对象模型,并且都具有 O(log n) 检索。 两个类的不同之处是在内存使用,并且插入和删除的速度︰

每个键/值对都可以作为 KeyValuePair<TKey,TValue> 结构,或指定为 DictionaryEntry 通过非泛型 IDictionary 接口。

密钥必须是固定不变,前提是它们被用作中的键进行 SortedDictionary<TKey,TValue>。 中的所有键 SortedDictionary<TKey,TValue> 必须是唯一的。 键不能为 null, ,但值则可以为,如果值类型 TValue 是引用类型。

 SortedDictionary<TKey,TValue> 需要一个比较器实现,以执行关键的比较。 您可以指定的一个实现 IComparer<T> 泛型接口的使用构造函数接受 comparer 参数; 如果未指定的实现,默认 genericcomparer Comparer<T>.Default 使用。 如果类型 TKey 实现 System.IComparable<T> 泛型接口,则默认比较器使用该实现。

 foreach C# 语言的语句 (for each c + + 中 For Each 在 Visual Basic 中) 返回集合中的元素的类型的对象。 由于每个元素的 SortedDictionary<TKey,TValue> 是一个键/值对,元素类型不是键的类型或值的类型。 相反,元素类型是 KeyValuePair<TKey,TValue>。 下面的代码演示 C#、 c + + 和 Visual Basic 语法。

foreach( KeyValuePair<string, string> kvp in myDictionary )
{
    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}

foreach 语句是枚举器,它允许仅从集合读取,不向其写入周围的包装。


示例

下面的代码示例创建一个空 SortedDictionary<TKey,TValue> 具有字符串键和使用的字符串 Add 方法来添加一些元素。 该示例演示 Add 方法抛出异常 ArgumentException 时尝试添加重复的键。

该示例使用 Item 属性 (在 C# 中为索引器) 来检索值,演示 KeyNotFoundException 请求的键不存在,并且可以替换与某个键相关联的值时引发。

该示例演示如何使用 TryGetValue 方法作为更高效的方法来检索值,如果某个程序必须经常尝试在字典中,不,演示如何使用 ContainsKey 方法来测试某个键是否存在,然后再调 Add 方法。

该示例演示如何枚举的键和值字典中的以及如何枚举键和值单独使用 Keys 属性和 Values 属性。

最后,该示例演示 Remove 方法。

using System;using System.Collections.Generic;public class Example
{    public static void Main()
    {       
     // Create a new sorted dictionary of strings, with string
        // keys.
        SortedDictionary<string, string> openWith = 
            new SortedDictionary<string, string>();        
        // Add some elements to the dictionary. There are no 
        // duplicate keys, but some of the values are duplicates.
        openWith.Add("txt", "notepad.exe");
        openWith.Add("bmp", "paint.exe");
        openWith.Add("dib", "paint.exe");
        openWith.Add("rtf", "wordpad.exe");        
        // The Add method throws an exception if the new key is 
        // already in the dictionary.
        try
        {
            openWith.Add("txt", "winword.exe");
        }        
        catch (ArgumentException)
        {
            Console.WriteLine("An element with Key = \"txt\" already exists.");
        }        
        // The Item property is another name for the indexer, so you 
        // can omit its name when accessing elements. 
        Console.WriteLine("For key = \"rtf\", value = {0}.", 
            openWith["rtf"]);        
        // The indexer can be used to change the value associated
        // with a key.
        openWith["rtf"] = "winword.exe";
        Console.WriteLine("For key = \"rtf\", value = {0}.", 
            openWith["rtf"]);        
        // If a key does not exist, setting the indexer for that key
        // adds a new key/value pair.
        openWith["doc"] = "winword.exe";        
        // The indexer throws an exception if the requested key is
        // not in the dictionary.
        try
        {
            Console.WriteLine("For key = \"tif\", value = {0}.", 
                openWith["tif"]);
        }        
        catch (KeyNotFoundException)
        {
            Console.WriteLine("Key = \"tif\" is not found.");
        }        
        // When a program often has to try keys that turn out not to
        // be in the dictionary, TryGetValue can be a more efficient 
        // way to retrieve values.
        string value = "";        
        if (openWith.TryGetValue("tif", out value))
        {
            Console.WriteLine("For key = \"tif\", value = {0}.", value);
        }        
        else
        {
            Console.WriteLine("Key = \"tif\" is not found.");
        }        
        // ContainsKey can be used to test keys before inserting 
        // them.
        if (!openWith.ContainsKey("ht"))
        {
            openWith.Add("ht", "hypertrm.exe");
            Console.WriteLine("Value added for key = \"ht\": {0}", 
                openWith["ht"]);
        }        
        // When you use foreach to enumerate dictionary elements,
        // the elements are retrieved as KeyValuePair objects.
        Console.WriteLine();        
        foreach( KeyValuePair<string, string> kvp in openWith )
        {
            Console.WriteLine("Key = {0}, Value = {1}", 
                kvp.Key, kvp.Value);
        }        
        // To get the values alone, use the Values property.
        SortedDictionary<string, string>.ValueCollection valueColl = 
            openWith.Values;        
        // The elements of the ValueCollection are strongly typed
        // with the type that was specified for dictionary values.
        Console.WriteLine();        
        foreach( string s in valueColl )
        {
            Console.WriteLine("Value = {0}", s);
        }       
         // To get the keys alone, use the Keys property.
        SortedDictionary<string, string>.KeyCollection keyColl = 
            openWith.Keys;        
        // The elements of the KeyCollection are strongly typed
        // with the type that was specified for dictionary keys.
        Console.WriteLine();        
        foreach( string s in keyColl )
        {
            Console.WriteLine("Key = {0}", s);
        }        
        // Use the Remove method to remove a key/value pair.
        Console.WriteLine("\nRemove(\"doc\")");
        openWith.Remove("doc");       
         if (!openWith.ContainsKey("doc"))
        {
            Console.WriteLine("Key \"doc\" is not found.");
        }
    }
}
/* This code example produces the following output:

An element with Key = "txt" already exists.
For key = "rtf", value = wordpad.exe.
For key = "rtf", value = winword.exe.
Key = "tif" is not found.
Key = "tif" is not found.
Value added for key = "ht": hypertrm.exe

Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = doc, Value = winword.exe
Key = ht, Value = hypertrm.exe
Key = rtf, Value = winword.exe
Key = txt, Value = notepad.exe

Value = paint.exe
Value = paint.exe
Value = winword.exe
Value = hypertrm.exe
Value = winword.exe
Value = notepad.exe

Key = bmp
Key = dib
Key = doc
Key = ht
Key = rtf
Key = txt

Remove("doc")
Key "doc" is not found.
 */

备注:转自https://msdn.microsoft.com/zh-cn/library/f7fta44c(v=vs.110).aspx