C # advanced programming (10) -- LINQ

Source: Internet
Author: User

LINQ unifies the data access mode, which serves as a bridge between the programming language and data. LINQ framework: it consists of three parts: Language extension, LINQ build block, and Assembly provision.

For the following code:
Varquery = from book in SampleData. Books
Where book. Title = "Funny Stories"
Orderby book. Title
Select new {book. Title, book. Price };
It is equivalent:
Varquery = SampleData. Books
. Where (book => book. Title = "Funny Stories ")
. OrderBy (book => book. Title)
. Select (book => new {book. Title, book. Price });
The compiler converts it to the following call:
IEnumerable <double> query = Enumerable. Select <int, double> (
Enumerable. OrderBy (\
Enumerable. Where (
SampleData. Books,
Book => book. Title = "Funny Stories "),
Book => book. Title ),
Book => new {book. Title, book. Price });
Many LINQ methods are defined in the System. Linq. Enumerable class. These methods are implemented as extension methods.
. NET implements the IEnumerable <T> interface object to become an iteratable object, the iteratable object will return an iterator (the object that implements the IEnumerator <T> Interface ), you can use the iterator to traverse the iterated objects.
Some extension methods in the Enumerable class accept parameters of the IEnumerable <T> type and return the results of IEnumerable <T>. Therefore, they are equivalent to filters in the processing process. These methods only return iteratable objects, and do not return the query results. They are executed only when an iteratable object is called (for example, foreach, this is a very important feature of LINQ-latency query.

Related Article

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.