One of the most common query operations is obviously to filter out elements based on certain conditions. Those conditions can either be on a per-element basis (such as with the Where operator) or have a more global nature (as with Skip or Take). In essence, we’re talking here about horizontal partitioning where a given number of objects in the input sequence are filtered down to a subset. Those restriction operators don’t change the shape of the data and preserve the type of the input sequence.


The first restriction operator is one we’re already familiar with. The Where operator evaluates a condition for each element in the input sequence, only retaining objects for which the condition evaluated to true. Two overloads exist: ...

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.