6.1. Query a Generic Collection

Problem

You need to query data that is stored in a collection that implements IEnumerable(Of T).

Solution

Create a general LINQ query, using the From clause, to iterate through the data stored in the target collection.

How It Works

LINQ to Objects, represented by the System.Linq namespace, extends the core LINQ framework and provides the mechanisms necessary to query data stored in objects that inherit IEnumerable(Of T). Querying IEnumerable objects is also supported but requires an extra step, which is covered in recipe 6-2.

A standard query consists of one or more query operators that query the given data source and return the specified results. If you have any familiarity with Structured Query Language (SQL), ...

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.