© Dmitri Nesteruk 2019
Dmitri NesterukDesign Patterns in .NEThttps://doi.org/10.1007/978-1-4842-4366-4_17

17. Iterator

Dmitri Nesteruk1 
(1)
St. Petersburg, c.St-Peterburg, Russia
 

An Iterator, put simply, is an object that is used to traverse some structure or other. Typically, the Iterator references the currently accessed element and has a method to move forward. A bidirectional Iterator also lets you lets you walk backward, and a random-access Iterator allows you to access an element at an arbitrary position.

In .NET, the thing that enables the Iterator pattern (the .NET framework uses the term enumerator instead) typically implements the IEnumerator<T> interface . It has the following members:
  • Current refers to the element at the current position. ...

Get Design Patterns in .NET: Reusable Approaches in C# and F# for Object-Oriented Software Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.