LINQ series: Fundamentals and Nature (part I)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.