Returning IEnumerable<T>, Yielding, and Deferred Queries

It is important to remember that while many of the Standard Query Operators are prototyped to return an IEnumerable<T>, and we think of IEnumerable<T> as a sequence, the operators are not actually returning the sequence at the time the operators are called. Instead, the operators return an object that when enumerated will yield an element from the sequence. It is during enumeration of the returned object that the query is actually performed and an element is yielded to the output sequence. In this way, the query is deferred.

In case you are unaware, when I use the term yield, I am referring to the C# 2.0 yield keyword that was added to the C# language to make writing enumerators easier. ...

Get Pro LINQ: Language Integrated Query in C# 2008 now with O’Reilly online learning.

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