Linq Coding-Part Two [standard query operator]

Source: Internet
Author: User
Standard query operator
1. In LINQ, the query variable itself does not perform any operations and does not return any data.
It only stores the information necessary to generate results when a query is executed at a later time.
2. The "standard query operator" is a method that forms the Language Integrated Query (LINQ) mode.
There are two groups of standard query operators for LINQ, one running on an object of the IEnumerable (T) type and the other running on an object of the IQueryable (T) type.
* If you must reference the results of group operations, you can use the into keyword to create an identifier that can be further queried.

1 class StandSearchToLinq: Interface
2 {
3 # region Interface Members
4
5 public void invoke ()
6 {
7 string sentence = "the quick brown fox jumps over the lazy dog ";
8 string [] words = sentence. Split ('');
9 // standard query
10 var query = from word in words
11 group word. ToUpper () by word. Length into gr
12 orderby gr. Key
13 select new {Length = gr. Key, Words = gr };
14
15 // Lambda
16 var query2 = words. groupBy (w => w. length, w => w. toUpper ()). select (g => new {Length = g. key, Words = g }). orderBy (o => o. length );
17
18 foreach (var obj in query2)
19 {
20 Console. WriteLine ("Words of Length {0}:", obj. Length );
21 foreach (string word in obj. Words)
22 Console. WriteLine (word );
23}
24}
25
26 # endregion
27}

 

 

LINQ Coding directory

  1. Linq Coding -- Part One
  2. Linq Coding -- Part Two [standard query operator]
  3. Linq Coding -- Part Three [Let clause]
  4. Linq Coding -- Part Four [Concat application]
  5. Linq Coding -- Part Five (Join Internal Join query)
  6. Linq Coding -- Part Six (Join Group Join)
  7. Linq Coding -- Part Seven (Join: left Outer Join, DefaultIfEmpty, GroupJoin)

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.