Information Technology Reference
In-Depth Information
The enumerator class is usually declared as a nested class of the class for which it is an
enumerator. A nested class is one that is declared inside the declaration of another class.
The way the enumerator keeps track of the current item in the sequence is entirely
implementation-dependent. It might be implemented as a reference to an object, an index
value, or something else entirely. In the case of an array, it is simply the index of the item.
Figure 20-3 illustrates the states of an enumerator for a collection of three items.
￿
Notice that the initial position of the enumerator is -1 (i.e., before the first element of the
collection).
￿
Each transition between states is caused by a call to MoveNext , which advances the posi-
tion in the sequence. Each call to MoveNext between states 1 and 4 returns true . In the
transition between states 4 and 5, however, the position ends up beyond the last item in
the collection, so the method returns false .
In the final state, any further calls to MoveNext return false .
￿
Figure 20-3. The states of an enumerator
Search WWH ::




Custom Search