Knowledge Summary of LINQ

Source: Internet
Author: User

Summary of the LINQ syntax:
There are two types of syntaxes available for you to use when writing a LINQ query: "query syntax" and "method Syntax ".
1) first read a column and have an intuitive understanding
Int [] arr = {12, 45 };
// The query syntax format (this is recommended), returns an enumerated type
Ienumerable <int> Results = from temp in arr
Where temp> 20
Select temp;

// Method (also called standard query operator) syntax form
Int max = arr. Max ();
2) Details:
A. query syntax:
Some statements that must be understood: From, select | group (start and end) must be dropped. The optional statements in the query body include where, from, let, join, and,
There are also anonymous types, such as VAR person = new {name = 'Ls', age = 24}, which are commonly used in select statements.


B. Standard query operators (in the form of method syntax): All query operators (methods) are declared in sysytem. LINQ. enumerable, which is a method for expanding ienumerable <t>.
It must be understood that the queried collection object is called a "sequence" and must implement the ienumerable <t> interface (why? These operators are all extensions of the ienumerable <t> generic interface (extended in the enumerable class); standard query operators use method syntax (which can be considered as one thing ); some operators return the enumerated type (such as where), or a table volume (such as Count returns an integer ). The operator that returns a scalar is executed immediately. If it returns an enumerated type, it is delayed iteration, that is, it is called only when the scalar is called.
There are also anonymous methods, which are commonly used in standard query operator method parameters (delegate type parameters): Delegate (parameter list) {method body}
Lambada expressions are commonly used in anonymous methods instead of (input parameter) => expr

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.