Beginning Microsoft® Visual C#® 2008
by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White
Chapter 26. Introduction to LINQ
This chapter introduces Language-Integrated Query (LINQ), a new extension to the C# language just added for C# 3.0, which is the C# language supported in Visual C# 2008. LINQ solves the problem of dealing with very large collections of objects, where you typically need to select a subset of the collection for the task your program is performing.
In the past, this sort of work required writing a lot of looping code, and additional processing such as sorting or grouping the found objects required even more code. LINQ frees you from having to write this extra looping code to filter and sort. It enables you to focus on the objects that matter to your program, providing a query.
In addition to providing an elegant query language that enables you to specify exactly what objects you are searching for, LINQ offers many extension methods that make it easy to sort, group, and calculate statistics on your query results.
LINQ also enables you to query large databases or complex XML documents in which millions or even billions of objects need to be searched or manipulated efficiently. Traditionally, this problem was usually solved with a specialized class library or even using a different language, such as database query language SQL. However, class libraries are not easy to extend for many different types of objects, and mixing languages causes problems with mismatched types, as well as making programs hard to understand for developers not familiar with both languages, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access