Mono Class Library: System.Collections.IEnumerator Overview | Members

System.Collections.IEnumerator.MoveNext Method

Advances the current instance to the next element of the collection. [Edit]

public bool MoveNext ()

Returns

true if the current instance was successfully advanced to the next element; false if the current instance has passed the end of the collection. [Edit]

Exceptions

TypeReason
InvalidOperationExceptionThe collection was modified after the current instance was instantiated. [Edit]

Remarks

Note: When the current instance is constructed or after IEnumerator.Reset is called, the current instance is positioned immediately before the first element of the collection. Use IEnumerator.MoveNext to position it over the first element of the collection.

Operation
A call to IEnumerator.MoveNext is required to position the current instance over the next element in the collection and return true if the current instance was not positioned beyond the last element of the collection when IEnumerator.MoveNext was called. If the current instance is already positioned immediately after the last element of the collection, a call to IEnumerator.MoveNext is required to return false, and the current instance is required to remain in the same position. If elements are added, removed, or repositioned in the collection after the current instance was instantiated, it is required that a call to IEnumerator.MoveNext throw InvalidOperationException.

Usage
Use the IEnumerator.MoveNext method to check if the current instance is positioned immediately after the last element of the collection, and to position it over the next element if it is not already past the last element of the collection. This allows the use of a conditional loop to iterate over the entire collection.

[Edit]

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0