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.

Range

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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.