HashSet<T>.Enumerator.IEnumerator.Reset Method


將列舉值設定為其初始位置,在集合的第一個元素之前。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 方法,將列舉值前移至集合的第一個元素,然後再讀取 Current 屬性的值。After calling IEnumerator.Reset, 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. 如果對集合進行了變更,例如加入、修改或刪除專案,枚舉器會失效,且下一次呼叫 MoveNextIEnumerator.Reset 會擲回 InvalidOperationExceptionIf changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to MoveNext or IEnumerator.Reset throws an InvalidOperationException.

Applies to