About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Iterators

As a precursor to the LINQ feature set, C# 2.0 introduced the concept of iterators to make the definition of IEnumerable<T> and IEnumerator<T> objects easier. You’ve seen before how powerful custom implementations of those interfaces can be (for example, to yield a sequence of numbers to a consumer, in an on-demand basis). All you need to do is respond properly to MoveNext method and Current property getter calls.

Conceptually though, your task is even simpler: You just want to hand out objects to a consumer when asked to do so. This feels quite a bit like returning data from a method, the difference being you don’t just return a single object but a sequence of objects, one at a time.

Iterators precisely enable you to do this, using ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required