O'Reilly logo

Beginning Microsoft® Visual C#® 2008 by Eric White, Morgan Skinner, Jon D. Reid, Jacob Hammer Pedersen, Christian Nagel, Karli Watson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required