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:

image

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

image

Now we can ...

Get C# 4.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.