6.5. Filter Data Using LINQ

Problem

You need to query data that is stored in a collection, but you need to apply some constraint, or filter, to the data in order to limit the scope of the query.

Solution

Create a standard LINQ query, such as the ones described in the previous recipes, and use the Where clause to specify how the data should be filtered.

How It Works

While the Select clause (see recipe 6-3) is responsible for transforming or returning data from a LINQ query, the Where clause is responsible for filtering what data is available to be returned. If you are familiar with SQL, the LINQ Where clause is virtually indistinguishable from the like-named clause in SQL. A Boolean expression, which is used to perform the data filtering, precedes ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach 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.