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 }
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 }