In-Memory Data

Starting from the same in-memory collection of products, we want to get rid of our imperative code that obfuscated the meaning of our query before. Here, we’re using the LINQ to Objects implementation, which implements the query pattern for objects that implement IEnumerable<T>. Given the following data source, we want to express a query that will give us back only the products with a price less than $25:


Instead of iterating over the elements ourselves, we can use a LINQ query expression and simply declare our intent:


Now we can ...

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

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