Dictionary<TKey,TValue>.Enumerator.IEnumerator.Reset 方法

定义

将枚举数设置为其初始位置,该位置位于集合中第一个元素之前。Sets the enumerator to its initial position, which is before the first element in the collection.

 virtual void System.Collections.IEnumerator.Reset() = System::Collections::IEnumerator::Reset;
void IEnumerator.Reset ();
abstract member System.Collections.IEnumerator.Reset : unit -> unit
override this.System.Collections.IEnumerator.Reset : unit -> unit
Sub Reset () Implements IEnumerator.Reset

实现

例外

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

注解

调用方法后 IEnumerator.Reset ,必须调用 MoveNext 方法,以将枚举器前进到集合的第一个元素,然后再读取属性的值 CurrentAfter calling the IEnumerator.Reset method, you must call the MoveNext method to advance the enumerator to the first element of the collection before reading the value of the Current property.

只要集合保持不变,枚举器就仍有效。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.

适用于

另请参阅