Dictionary<TKey,TValue>.KeyCollection Class

Definition

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)

Type Parameters

TKey
TValue
Inheritance
Dictionary<TKey,TValue>.KeyCollection
Attributes
Implements

Remarks

The Dictionary<TKey,TValue>.Keys property returns an instance of this type, containing all the keys in that Dictionary<TKey,TValue>. 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.

The 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>. Therefore, changes to the Dictionary<TKey,TValue> continue to be reflected in the Dictionary<TKey,TValue>.KeyCollection.

Constructors

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

Properties

Count

Gets the number of elements contained in the Dictionary<TKey,TValue>.KeyCollection.

Methods

CopyTo(TKey[], Int32)

Copies the Dictionary<TKey,TValue>.KeyCollection elements to an existing one-dimensional Array, starting at the specified array index.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

Returns an enumerator that iterates through the Dictionary<TKey,TValue>.KeyCollection.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

ICollection.IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

ICollection<TKey>.Add(TKey)

Adds an item to the ICollection<T>. This implementation always throws NotSupportedException.

ICollection<TKey>.Clear()

Removes all items from the ICollection<T>. This implementation always throws NotSupportedException.

ICollection<TKey>.Contains(TKey)

Determines whether the ICollection<T> contains a specific value.

ICollection<TKey>.IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

ICollection<TKey>.Remove(TKey)

Removes the first occurrence of a specific object from the ICollection<T>. This implementation always throws NotSupportedException.

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

IEnumerable<TKey>.GetEnumerator()

Returns an enumerator that iterates through a collection.

Extension Methods

CopyToDataTable<T>(IEnumerable<T>)

Returns 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)

Copies 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)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

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)

Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

Returns a collection of the descendant nodes of every document and element in the source collection.

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)

Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

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)

Returns a filtered collection of the child elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

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

Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

Removes every node in the source collection from its parent node.

Applies to

Thread Safety

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

A 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.