Dictionary<TKey,TValue>.Enumerator.IDictionaryEnumerator.Key 属性


获取位于枚举数当前位置的元素的键。Gets the key of the element at the current position of the enumerator.

property System::Object ^ System::Collections::IDictionaryEnumerator::Key { System::Object ^ get(); };
object System.Collections.IDictionaryEnumerator.Key { get; }
object? System.Collections.IDictionaryEnumerator.Key { get; }
member this.System.Collections.IDictionaryEnumerator.Key : obj
 ReadOnly Property Key As Object Implements IDictionaryEnumerator.Key



字典中位于枚举数当前位置的元素的键。The key of the element in the dictionary at the current position of the enumerator.




枚举器位于集合中第一个元素之前或最后一个元素之后。The enumerator is positioned before the first element of the collection or after the last element.


IDictionaryEnumerator.Key 在以下任何条件下均未定义:IDictionaryEnumerator.Key is undefined under any of the following conditions:

  • 枚举器位于集合的第一个元素之前。The enumerator is positioned before the first element of the collection. 在创建枚举器之后或在 IEnumerator.Reset 调用方法之后发生。That happens after an enumerator is created or after the IEnumerator.Reset method is called. MoveNext 读取属性的值之前,必须调用方法以将枚举数前移到集合的第一个元素 IDictionaryEnumerator.KeyThe 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.

  • 对返回的的最后一个调用 MoveNext false ,它指示集合的末尾,枚举数置于集合的最后一个元素之后。The last call to MoveNext returned false, which indicates the end of the collection and that the enumerator is positioned after the last element of the collection.

  • 由于对集合所做的更改(如添加、修改或删除元素),枚举器无效。The enumerator is invalidated due to changes made in the collection, such as adding, modifying, or deleting elements.

IDictionaryEnumerator.Key 不移动枚举器的位置,并且连续调用将 IDictionaryEnumerator.Key 返回相同的对象,直到 MoveNext IEnumerator.Reset 调用或。IDictionaryEnumerator.Key does not move the position of the enumerator, and consecutive calls to IDictionaryEnumerator.Key return the same object until either MoveNext or IEnumerator.Reset is called.