1 public class LetFromLinq : Interface
2 {
3 #region Interface Members
4
5 public void invoke()
6 {
7 String[] strs = { "A penny saved is a penny earned.",
8 "The early bird catches the worm.",
9 "The pen is mightier than the sword." };
10
11 //使查询只能对范围变量 word 调用一次 ToLower。如果不使用 let,则必须在 where 子句的每个谓词中调用 ToLower。
12 var earlyBirdQuery = from sentence in strs
13 let words = sentence.Split(' ') //用空格分隔strs数组
14 from word in words
15 let w = word.ToLower() //把数组元素进行小写操作
16 where w[0] == 'the'
17 select word;
18
19 foreach (var v in earlyBirdQuery)
20 {
21 Console.WriteLine("\"{0}\" starts with a vowel", v);
22 }
23
24 Console.WriteLine("Press any key to exit.");
25 Console.ReadKey();
26 }
27
28 #endregion
29 }
2 {
3 #region Interface Members
4
5 public void invoke()
6 {
7 String[] strs = { "A penny saved is a penny earned.",
8 "The early bird catches the worm.",
9 "The pen is mightier than the sword." };
10
11 //使查询只能对范围变量 word 调用一次 ToLower。如果不使用 let,则必须在 where 子句的每个谓词中调用 ToLower。
12 var earlyBirdQuery = from sentence in strs
13 let words = sentence.Split(' ') //用空格分隔strs数组
14 from word in words
15 let w = word.ToLower() //把数组元素进行小写操作
16 where w[0] == 'the'
17 select word;
18
19 foreach (var v in earlyBirdQuery)
20 {
21 Console.WriteLine("\"{0}\" starts with a vowel", v);
22 }
23
24 Console.WriteLine("Press any key to exit.");
25 Console.ReadKey();
26 }
27
28 #endregion
29 }