IEnumerable<T> and IEnumerator<T> Recap

To set the scene, we need to refresh our knowledge of the IEnumerable<T> interface and its little brother, IEnumerator<T>. The LINQ to Objects standard query operators are implemented as extension methods on the former interface, meaning that any query expressions can target any enumerable sequence. Because collection types implement this interface, this makes LINQ to Objects available for all of those (including arrays).

The IEnumerable<T> interface basically provides the capability to request an enumerator, which acts like a cursor over a sequence of objects of type T. Multiple enumerators can be active simultaneously, each with its own cursor into the underlying sequence:

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.