© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
D. NesterukDesign Patterns in .NET 6https://doi.org/10.1007/978-1-4842-8245-8_18

18. Iterator

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

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

In .NET, that thing that enables an iterator 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 6: 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.