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. Indeed, this is one of the core patterns of LINQ, as you’ll see in part 3 of the book.

6.1. C# 1: The pain of handwritten iterators

 

6.2. C# 2: Simple iterators with yield statements

 
 
 

6.3. Real-life iterator examples

 
 
 

6.4. Pseudo-synchronous code with the Concurrency and Coordination Runtime

 
 
 
 

6.5. Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage