
LINQ to Objects
Lessons 35 and 36 explain how you can use Visual Studio’s wizards to build simple database
programs. They show one of many ways to connect a program to a data source.
Language-Integrated Query (LINQ) provides another method for bridging the gap between a
program and data. Instead of simply providing another way to access data in a database, how-
ever, LINQ can help a program access data stored in many places. LINQ lets a program access
data stored in databases, arrays, collections, or files in basically the same way.
LINQ provides four basic technologies that give you access to data stored in various places:
LINQ to SQL
— Data stored in SQL Server databases
LINQ to Dataset
— Data stored in other databases
LINQ to XML
— Data stored in XML (eXtensible Markup Language) files
LINQ to Objects
— Data stored in collections, lists, arrays, strings, files, and so forth
In this lesson you learn how to use LINQ to Objects. You learn how to extract data from lists,
collections, and arrays, and how to process the results.
LINQ BASICS
Using LINQ to process data takes three steps:
1. Create a data source.
2. Build a query to select data from the data source.
3. Execute the query and process the result.
You might expect the third step to be two separate steps, “Execute the query” and “Process the
result.” In practice, however, LINQ doesn’t actually execute the query until it must ...