Dictionary<TKey,TValue>.Enumerator.MoveNext 方法

定义

使枚举数前进到 Dictionary<TKey,TValue> 的下一个元素。Advances the enumerator to the next element of the Dictionary<TKey,TValue>.

public:
 virtual bool MoveNext();
public bool MoveNext ();
abstract member MoveNext : unit -> bool
override this.MoveNext : unit -> bool
Public Function MoveNext () As Boolean

返回

Boolean

如果枚举数已成功地推进到下一个元素,则为 true;如果枚举数传递到集合的末尾,则为 falsetrue if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.

实现

例外

集合在枚举器创建后被修改。The collection was modified after the enumerator was created.

注解

创建枚举器后,枚举数将定位在集合中的第一个元素之前,第一次调用会将 MoveNext 枚举数前移到集合的第一个元素。After an enumerator is created, the enumerator is positioned before the first element in the collection, and the first call to MoveNext advances the enumerator to the first element of the collection.

如果 MoveNext 越过集合的末尾,则枚举器将定位在集合中最后一个元素之后,并 MoveNext 返回 falseIf MoveNext passes the end of the collection, the enumerator is positioned after the last element in the collection and MoveNext returns false. 当枚举器位于此位置时,对的后续调用 MoveNext 也将返回 falseWhen the enumerator is at this position, subsequent calls to MoveNext also return false.

只要集合保持不变,枚举器就仍有效。An enumerator remains valid as long as the collection remains unchanged. 如果对集合所做的更改(如添加元素或更改容量),则枚举器将失效且不可恢复,并且对或的下一个调用将 MoveNext IEnumerator.Reset 引发 InvalidOperationExceptionIf changes are made to the collection, such as adding elements or changing the capacity, the enumerator is irrecoverably invalidated and the next call to MoveNext or IEnumerator.Reset throws an InvalidOperationException.

仅限 .NET Core 3.0 +:不使枚举器无效的唯一改变方法是 RemoveClear.NET Core 3.0+ only: The only mutating methods which do not invalidate enumerators are Remove and Clear.

适用于

另请参阅