System.Collections.IDictionaryEnumerator.Key Property

Gets the key of the current dictionary entry.

Syntax

public object Key { get; }

Value

A object that contains the DictionaryEntry.Key of the DictionaryEntry in the collection over which the current instance is positioned.

Exceptions

TypeReason
InvalidOperationException

The IDictionaryEnumerator is positioned before the first element of the dictionary or after the last element.

-or-

The dictionary was modified after the IDictionaryEnumerator was instantiated.

Remarks

After an enumerator is created or after the IEnumerator.Reset method is called, the IEnumerator.MoveNext method must be called to advance the enumerator to the first element of the collection before reading the value of the IDictionaryEnumerator.Key property; otherwise, IDictionaryEnumerator.Key is undefined.

IDictionaryEnumerator.Key also throws an exception if the last call to IEnumerator.MoveNext returned false, which indicates the end of the collection.

IDictionaryEnumerator.Key does not move the position of the enumerator, and consecutive calls to IDictionaryEnumerator.Key return the same object until either IEnumerator.MoveNext or IEnumerator.Reset is called.

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0