HashSet<T>.Enumerator.MoveNext HashSet<T>.Enumerator.MoveNext HashSet<T>.Enumerator.MoveNext HashSet<T>.Enumerator.MoveNext Method


讓列舉程式前進至 HashSet<T> 集合中的下一個項目。Advances the enumerator to the next element of the HashSet<T> collection.

 virtual bool MoveNext();
public bool MoveNext ();
abstract member MoveNext : unit -> bool
override this.MoveNext : unit -> bool
Public Function MoveNext () As 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 the MoveNext method advances the enumerator to the first element of the collection.

如果MoveNext傳遞集合的結尾, 則列舉值會放置在集合中的最後一個元素之後false, MoveNext並傳回。If MoveNext passes the end of the collection, the enumerator is positioned after the last element in the collection and MoveNext returns false. 當列舉值在此位置時, 後續的呼叫MoveNext false也會傳回。When the enumerator is at this position, subsequent calls to MoveNext also return false.

只要集合維持不變,列舉程式就持續有效。An enumerator remains valid as long as the collection remains unchanged. 如果對集合進行了變更, 例如加入、修改或刪除專案, 枚舉器會失效, 且下一次呼叫MoveNextIEnumerator.Reset InvalidOperationException會擲回。If 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.