IEnumerator |
Name | Description |
---|---|
Current (get) | Gets the current element in the collection. |
Name | Description |
---|---|
MoveNext | Advances the enumerator to the next element of the collection. |
Reset | Requests the enumerator resets itself to begin enumerating from the beginning. |
The enumerator can be used manually to enumerate through the values of a list, or it can be wrapped in a custom enumerator to allow it to be used in the For..Each context.
To use an IEnumerator object in For..Each, call the CreateEnumerator method passing in the IEnumerator object. The returned value is then returned in the standard NewEnum(Procedure ID: -4) function called by For..Each. The enumeration will then be delegated to the custom IEnumerator object.
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