I've written some c#3.x new features before. Please refer to: c#3.x characteristics, we know that these new features are basically for the implementation of LINQ services, in the ordinary programming can also have a reasonable choice of application, but also effectively improve the coding efficiency, to achieve a more readable concise code. On the basis of understanding these features, understanding LINQ will become simpler.
1 Introduction to LINQ:
LINQ query Expressions (query expressions) can access objects, relational databases, datasets (datasets), and XML documents that implement ienumberable<t> interfaces in a uniform manner.
Strictly speaking, LINQ is a term used to describe a range of data access technologies. LINQ to Objects applies to objects that implement the Ienumberable<t> Interface, LINQ to SQL applies to relational databases, and LINQ to the DataSet is a subset of LINQ to SQL that LINQ to XML applies FOR XML documents. A LINQ query expression is strongly typed (strongly typed), so the compiler ensures its syntax is correct. LINQ is an extensible technology, and third parties can use extension functions to define new query operators.
2LINQ Core Assembly (Assembly)
At a minimum, you need to reference the System.Linq namespace, defined in System.Core.dll, and Visual Stuodio 2008 automatically adds the reference by default.
| System.Core.dll |
Defines the types that represent the core LINQ API. This is the one assembly your must have access to. |
| System.Data.Linq.dll |
Provides functionality for-using LINQ with Relational Databases (LINQ to SQL). |
| System.Data.DataSetExtensions.dll |
Defines a handful of types to integrate ado.net types into the LINQ Programming Paradigm (LINQ to DataSet). |
| System.Xml.Linq.dll |
Provides functionality for-using LINQ with XML document data (LINQ to XML). |
3 LINQ Examples
Code
1 static void QueryOverInts()
2 {
3 int[] numbers = { 10, 20, 28, 40, 1, 3, 5, 8 };
4 IEnumerable<int> subset = from i in numbers
5 where i < 10
6 select i;
7 IEnumerable<int> subset1 = numbers.Where( j => j < 10 ).
8 OrderBy( j => j );
9 foreach( int i in subset )
10 Console.WriteLine( "Item: {0}", i );
11 foreach( int i in subset1 )
12 Console.WriteLine( "Item: {0}", i );
13
14