Implement the IEnumerator interface in VB. NET
This object similar to parent-child relationship is often used in object-oriented design. For example, in my current project, there are order objects, I want to use the Iterator mode to encapsulate products under an order. The IEnumerator interface in dot Net is used for iteration, to support the for each operation in dot Net.
To implement the IEnumerator interface, you must implement the following functions to support operations on the IEnumerator interface:
Overridable ReadOnly Property Current () As Object
Current is used to obtain the Current object during iteration.
Public Overridable Function MoveNext () As Boolean
MoveNext is used to point the iteration pointer to the next object in the iteration process. Initially, the iteration Pointer Points to the beginning of the Set (before the first node). Once the collection ends, before calling Reset, false is returned for subsequent calls to MoveNext.
Overridable Sub Reset ()
Set the enumeration number to its initial position before the first element in the set.
As long as the Set remains unchanged, the enumerated number remains valid. If a set is modified (for example, adding, modifying, or deleting an element), the enumerated number is invalid and cannot be restored. The next call to MoveNext or Reset will cause InvalidOperationException.
The following is a specific image for implementing the IEnumerator interface.
'------------------------ Class implementing the IEnumerator interface ----------------------------------
Imports System. Collections
'The actual implementation here is the System. Collections. IEnumerable interface. IteratorProduct uses this interface to provide users with operations on the IEnumerator interface.
Public Class IteratorProduct: Implements System. Collections. IEnumerable
Private Products As Collection all Products whose collections are stored in the order
Private item As Integer =-1
Public Sub New ()