IEnumerator and its generic counterpart IEnumerator
The IEnumerator
and IEnumerator<T>
interfaces (in the System.Collections
and System.Collections.Generic
namespaces, respectively) facilitate iteration through items in a collection through three members:
- The
Current
property, which returns anobject
forIEnumerator
and aT
forIEnumerator<T>
. - The
MoveNext()
method, which returns abool
-true
if the enumerator successfully moved to the next item;false
if not. Note that the initial position of the enumerator is before the first item;MoveNext()
must be called to check there are any items beforeCurrent
should be used. - The
Reset()
method, which returns the state of the enumerator to its initial position (before the first item).
References: