9. 生成操作符—【LINQ标准查询操作符】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class Empty_LINQ
    {
        public static void Empty_Print()
        {
            string[] name1 = { "Asfs", "Steve" };
            string[] name2 = { "Joe", "Jhon", "Sawyer", "Sayid" };
            string[] name3 = { "Dave", "Kate", "Juliet", "Sara" };
 
            List<string[]> names = new List<string[]> { name1, name2, name3 };
            IEnumerable<string> nameList = names.Aggregate(Enumerable.Empty<string>(),
                (current, next) => next.Length > 2 ? current.Union(next) : current);
 
            foreach (string s in nameList)
            {
                Console.WriteLine(s);
            }
        }
 
        public static void Range_Print()
        {
            foreach (var item in Enumerable.Range(1,10))
            {
                Console.WriteLine(item.ToString());
            }
 
            foreach (var item in Enumerable.Range(1, 10).Reverse())
            {
                Console.WriteLine(item.ToString());
            }
 
            foreach (var item in Enumerable.Range(1, 5).Select(x => x * 5))
            {
                Console.WriteLine(item.ToString());
            }
        }
 
        public static void Repeat_Print()
        {
            foreach (var item in Enumerable.Repeat("I love you",3))
            {
                Console.WriteLine(item.ToString());
            }
        }
    }
posted @   CityWalker  阅读(171)  评论(0编辑  收藏  举报
努力加载评论中...
天天来
点击右上角即可分享
微信分享提示