Introduction to LINQ (C#)
Language-Integrated Query (LINQ) is an innovation introduced in the .NET Framework version 3.5 that bridges the gap between the world of objects and the world of data.
Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. LINQ makes a query a first-class language construct in C#. You write queries against strongly typed collections of objects by using language keywords and familiar operators.
You can write LINQ queries in C# for SQL Server databases, XML documents, ADO.NET Datasets, and any collection of objects that supports IEnumerable or the generic IEnumerable<T> interface. LINQ support is also provided by third parties for many Web services and other database implementations.
You can use LINQ queries in new projects, or alongside non-LINQ queries in existing projects. The only requirement is that the project target .NET Framework 3.5 or later.
The following illustration from Visual Studio shows a partially-completed LINQ query against a SQL Server database in both C# and Visual Basic with full type checking and IntelliSense support.
To learn more details about LINQ, start by becoming familiar with some basic concepts in the Getting Started section Getting Started with LINQ in C#, and then read the documentation for the LINQ technology in which you are interested:
SQL Server databases: LINQ to SQL
XML documents: LINQ to XML (C#)
ADO.NET Datasets: LINQ to DataSet
.NET collections, files, strings and so on: LINQ to Objects (C#)
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.