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

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 @ 2010-04-17 22:01  CityWalker  阅读(171)  评论(0编辑  收藏  举报
天天来