Design Pattern Examples
Overview of object-oriented design patterns
IIterator< TItemType > Interface Template Reference

Represents an iterator for some type. This is a forward-only iterator in that it can only start at 0 and increment through the items until done. More...

Inheritance diagram for IIterator< TItemType >:
Inheritance graph
Collaboration diagram for IIterator< TItemType >:
Collaboration graph

Public Member Functions

void Reset ()
 Start iteration from beginning of container.
 
TItemType? Next ()
 Retrieve the next item from the container.
 

Detailed Description

Represents an iterator for some type. This is a forward-only iterator in that it can only start at 0 and increment through the items until done.

Template Parameters
TItemTypeThe type of each item provided by the iterator

var iterator = container.GetItems(); for (var item in iterator.Next(); item != null; item = iterator.Next()) { // Use item here }

A generic type is used in this example so I didn't have to come up with either two iterators (one for ItemPair and the other for string) or one iterator that returned an object that would have to be cast to the appropriate type before using.

Definition at line 51 of file IteratorContainer_Class.cs.

Member Function Documentation

◆ Next()

TItemType? Next ( )

Retrieve the next item from the container.

Returns
Returns a TItemType object or null, if there are no more items in the iteration.

Implemented in Iterator< TItemType >.

◆ Reset()

void Reset ( )

Start iteration from beginning of container.

Implemented in Iterator< TItemType >.


The documentation for this interface was generated from the following file: