IEnumerator: MoveNext

MoveNext

Advances the enumerator to the next element of the collection.



 Public Function MoveNext ( ) As Boolean

Return Values

Boolean -  True if the enumerator was successfully advanced to the next element; False if the enumerator has passed the end of the collection.

Remarks

After an enumerator is created or after the Reset method is called, an enumerator is positioned before the first element of the collection, and the first call to the MoveNext method moves the enumerator over the first element of the collection.

If MoveNext passes the end of the collection, the enumerator is positioned after the last element in the collection and MoveNext returns False. When the enumerator is at this position, subsequent calls to MoveNext also return False until Reset is called.

Examples

The following example shows an implementation of the IEnumerator interface.

This example is part of a larger complete example for IEnumerable.

Option Explicit
Implements IEnumerator

Private mBase As EnumeratorBase
Private mContainer As Container


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   Constructors
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub Init(ByVal Container As Container)
    Set mBase = NewEnumeratorBase(0, Container.Count)
    Set mContainer = Container
End Sub


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   IEnumerator
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get IEnumerator_Current() As Variant
    MoveVariant IEnumerator_Current, mContainer.Item(mBase.Index)
End Property

Private Function IEnumerator_MoveNext() As Boolean
    IEnumerator_MoveNext = mBase.MoveNext
End Function

Private Sub IEnumerator_Reset()
    mBase.Reset
End Sub

See Also

Project CorLib Overview

Class IEnumerator Overview