List<T>.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 IEnumerator.Reset, you must call MoveNext to advance the enumerator to the first element of the collection before reading the value of Current.

只要集合維持不變,列舉值就仍維持有效。An enumerator remains valid as long as the collection remains unchanged. 如果對集合進行了變更,例如加入、修改或刪除元素,列舉值將無法回復地失效,且下一次呼叫會擲回 IEnumerator.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 IEnumerator.Reset throws an InvalidOperationException.