Source Generators

Source generators comprise our first big category of standard query operators. Although different source objects can be LINQ-enabled (for example, by implementing IEnumerable<T> for local query execution or by implementing IQueryable<T> for remote query execution; for example, as used in LINQ to SQL), it sometimes makes sense to create a sequence on-the-fly.

All the methods discussed here live on the Enumerable type and provide a means to generate a source without persisting it in memory, thanks to lazy evaluation. Obviously, you can also use array, lists, or other collection types as in-memory data sources, but with immediate memory-allocation needs.


The first source generator is called Range and produces Int32 values ...

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.