Lecture overview -- Keyboard shortcut: 'u'  Previous page: Patterns and Techniques [Section] -- Keyboard shortcut: 'p'  Next page: Making iterators with yield return -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 34 : 36
Object-oriented Programming in C#
Collection Classes
The Iterator Design Pattern

The Iterator design pattern provides sequential access to an aggregated collection.

Iterators are known as Enumerators in C#.

 

  • Qualities of Iterators

    • Provides for a smaller client interface of the collection class

      • All members associated with traversals have been refactored to the iterator class

    • Makes it possible to have several simultaneous traversals

    • Does not reveal the internal representation of the collection

In C# iterators are typically used indirectly, via foreach.

Still, it is possible to used iterators directly.

Go to exerciseExplicit use of iterator - instead of using foreach
Go to exerciseUsing multiple interators