Chapter 6. Implementing iterators the easy way

This chapter covers

  • Implementing iterators in C# 1
  • Iterator blocks in C# 2
  • Sample iterator usage
  • Iterators as coroutines

The iterator pattern is an example of a behavioral pattern—a design pattern that simplifies communication between objects. It’s one of the simplest patterns to understand, and it’s incredibly easy to use. In essence, it allows you to access all the elements in a sequence of items without caring about what kind of sequence it is—an array, a list, a linked list, or none of the above. This can be effective for building a data pipeline, where an item of data enters the pipeline and goes through a number of different transformations or filters before coming out the other end. ...

Get C# in Depth, Third Edition 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.