Dictionary<TKey,TValue>.KeyCollection Dictionary<TKey,TValue>.KeyCollection Dictionary<TKey,TValue>.KeyCollection Dictionary<TKey,TValue>.KeyCollection Class

定义

表示 Dictionary<TKey,TValue> 中键的集合。Represents the collection of keys in a Dictionary<TKey,TValue>. 此类不能被继承。This class cannot be inherited.

public: ref class Dictionary<TKey, TValue>::KeyCollection sealed : System::Collections::Generic::ICollection<TKey>, System::Collections::Generic::IEnumerable<TKey>, System::Collections::Generic::IReadOnlyCollection<TKey>, System::Collections::ICollection
[System.Serializable]
public sealed class Dictionary<TKey,TValue>.KeyCollection : System.Collections.Generic.ICollection<TKey>, System.Collections.Generic.IEnumerable<TKey>, System.Collections.Generic.IReadOnlyCollection<TKey>, System.Collections.ICollection
type Dictionary<'Key, 'Value>.KeyCollection = class
    interface ICollection<'Key>
    interface ICollection
    interface IReadOnlyCollection<'Key>
    interface seq<'Key>
    interface IEnumerable
Public NotInheritable Class Dictionary(Of TKey, TValue).KeyCollection
Implements ICollection, ICollection(Of TKey), IEnumerable(Of TKey), IReadOnlyCollection(Of TKey)

类型参数

TKey
TValue
继承
Dictionary<TKey,TValue>.KeyCollectionDictionary<TKey,TValue>.KeyCollectionDictionary<TKey,TValue>.KeyCollectionDictionary<TKey,TValue>.KeyCollection
属性
实现

注解

属性返回此类型的实例, 其中包含Dictionary<TKey,TValue>中的所有键。 Dictionary<TKey,TValue>.KeysThe Dictionary<TKey,TValue>.Keys property returns an instance of this type, containing all the keys in that Dictionary<TKey,TValue>. Dictionary<TKey,TValue>.KeyCollection键的顺序未指定, 但与Dictionary<TKey,TValue>.Values属性返回的Dictionary<TKey,TValue>.ValueCollection中的关联值顺序相同。The order of the keys in the Dictionary<TKey,TValue>.KeyCollection is unspecified, but it is the same order as the associated values in the Dictionary<TKey,TValue>.ValueCollection returned by the Dictionary<TKey,TValue>.Values property.

不是静态副本; 而Dictionary<TKey,TValue>.KeyCollection是指返回到原始Dictionary<TKey,TValue>中的键。 Dictionary<TKey,TValue>.KeyCollectionThe Dictionary<TKey,TValue>.KeyCollection is not a static copy; instead, the Dictionary<TKey,TValue>.KeyCollection refers back to the keys in the original Dictionary<TKey,TValue>. 因此, 对的Dictionary<TKey,TValue>更改将继续反映Dictionary<TKey,TValue>.KeyCollection在中。Therefore, changes to the Dictionary<TKey,TValue> continue to be reflected in the Dictionary<TKey,TValue>.KeyCollection.

构造函数

Dictionary<TKey,TValue>.KeyCollection(Dictionary<TKey,TValue>) Dictionary<TKey,TValue>.KeyCollection(Dictionary<TKey,TValue>) Dictionary<TKey,TValue>.KeyCollection(Dictionary<TKey,TValue>) Dictionary<TKey,TValue>.KeyCollection(Dictionary<TKey,TValue>)

初始化 Dictionary<TKey,TValue>.KeyCollection 类的新实例,该实例反映指定的 Dictionary<TKey,TValue> 中的键。Initializes a new instance of the Dictionary<TKey,TValue>.KeyCollection class that reflects the keys in the specified Dictionary<TKey,TValue>.

属性

Count Count Count Count

获取 Dictionary<TKey,TValue>.KeyCollection 中包含的元素数。Gets the number of elements contained in the Dictionary<TKey,TValue>.KeyCollection.

方法

CopyTo(TKey[], Int32) CopyTo(TKey[], Int32) CopyTo(TKey[], Int32) CopyTo(TKey[], Int32)

从指定数组索引开始将 Dictionary<TKey,TValue>.KeyCollection 元素复制到现有一维 Array 中。Copies the Dictionary<TKey,TValue>.KeyCollection elements to an existing one-dimensional Array, starting at the specified array index.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回循环访问 Dictionary<TKey,TValue>.KeyCollection 的枚举数。Returns an enumerator that iterates through the Dictionary<TKey,TValue>.KeyCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

从特定的 ICollection 索引开始,将 Array 的元素复制到一个 Array 中。Copies the elements of the ICollection to an Array, starting at a particular Array index.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

获取可用于同步对 ICollection 的访问的对象。Gets an object that can be used to synchronize access to the ICollection.

ICollection<TKey>.Add(TKey) ICollection<TKey>.Add(TKey) ICollection<TKey>.Add(TKey) ICollection<TKey>.Add(TKey)

将某项添加到 ICollection<T> 中。Adds an item to the ICollection<T>. 此实现始终引发 NotSupportedExceptionThis implementation always throws NotSupportedException.

ICollection<TKey>.Clear() ICollection<TKey>.Clear() ICollection<TKey>.Clear() ICollection<TKey>.Clear()

ICollection<T> 中移除所有项。Removes all items from the ICollection<T>. 此实现始终引发 NotSupportedExceptionThis implementation always throws NotSupportedException.

ICollection<TKey>.Contains(TKey) ICollection<TKey>.Contains(TKey) ICollection<TKey>.Contains(TKey) ICollection<TKey>.Contains(TKey)

确定 ICollection<T> 是否包含特定值。Determines whether the ICollection<T> contains a specific value.

ICollection<TKey>.IsReadOnly ICollection<TKey>.IsReadOnly ICollection<TKey>.IsReadOnly ICollection<TKey>.IsReadOnly

获取一个值,该值指示 ICollection<T> 是否为只读。Gets a value indicating whether the ICollection<T> is read-only.

ICollection<TKey>.Remove(TKey) ICollection<TKey>.Remove(TKey) ICollection<TKey>.Remove(TKey) ICollection<TKey>.Remove(TKey)

ICollection<T> 中移除特定对象的第一个匹配项。Removes the first occurrence of a specific object from the ICollection<T>. 此实现始终引发 NotSupportedExceptionThis implementation always throws NotSupportedException.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

IEnumerable<TKey>.GetEnumerator() IEnumerable<TKey>.GetEnumerator() IEnumerable<TKey>.GetEnumerator() IEnumerable<TKey>.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

扩展方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于

线程安全性

此类型的Shared公共静态 (在 Visual Basic) 成员是线程安全的。Public static (Shared in Visual Basic) members of this type are thread safe. 但不保证所有实例成员都是线程安全的。Any instance members are not guaranteed to be thread safe.

只要不修改集合,就可以同时支持多个读取器。Dictionary<TKey,TValue>.KeyCollectionA Dictionary<TKey,TValue>.KeyCollection can support multiple readers concurrently, as long as the collection is not modified. 尽管如此, 枚举集合本身并不是一个线程安全的过程。Even so, enumerating through a collection is intrinsically not a thread-safe procedure. 若要确保枚举过程中的线程安全性,可以在整个枚举过程中锁定集合。To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. 若要允许多个线程访问集合以进行读写操作,则必须实现自己的同步。To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.