O'Reilly logo

C# 4.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Peek at Iterators

image Now that you’ve learned about iteration constructs in general and the foreach loop’s capability to deal with IEnumerable objects, we’re in an ideal position to introduce the concept of iterators. So far, all enumeration sources we’ve seen are collections of some sort. But what about creating our own sources to provide sequences of data consumable through enumeration?

Observe the true nature of the foreach loop first. In its true essence, it pulls data from some sequence of elements by querying that sequence using the MoveNext and Current members. Nothing requires the data returned to be available before the iteration starts; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required