Linq Coding -- Part Two[标准查询运算符]

标准查询运算符
 
1.      在 LINQ 中,查询变量本身不执行任何操作并且不返回任何数据。
       它只是存储在以后某个时刻执行查询时为生成结果而必需的信息。
2.      标准查询运算符”是组成语言集成查询 (LINQ) 模式的方法.
      共有两组 LINQ 标准查询运算符,一组在类型为 IEnumerable(T)的对象上运行,另一组在类型为 IQueryable(T)的对象上运行。
* into 如果您必须引用组操作的结果,可以使用 into 关键字来创建可进一步查询的标识符。
 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  // 标准查询
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 目录

  1. Linq Coding -- Part One
  2. Linq Coding -- Part Two[标准查询运算符]
  3. Linq Coding -- Part Three [Let子句]
  4. Linq Coding -- Part Four[Concat应用]
  5. Linq Coding -- Part Five (Join之内部联接查询)
  6. Linq Coding -- Part Six (Join之分组联接)
  7. Linq Coding -- Part Seven (Join之左外部联接、DefaultIfEmpty、GroupJoin)

你可能感兴趣的:(Linq Coding -- Part Two[标准查询运算符])