14. 分割操作符—【LINQ标准查询操作符】

public class Skip_LINQ
    {
        public static void Skip_Print()
        {
            int[] random = { 87, 2, 76, 90, 100, 65, 5, 22, 70 };
            //IEnumerable<int> query = random.OrderBy(r => r).Skip(4);
            IEnumerable<int> query2 = from r in random 
                                      orderby r 
                                      select r;
            foreach (int item in query2.Skip(4))
            {
                Console.WriteLine(item.ToString());
            }
        }

        public static void SkipWhile_Print()
        {
            int[] random = { 87, 2, 76, 90, 100, 65, 5, 22, 70 };
            IEnumerable<int> query = random.OrderBy(r => r).SkipWhile(r => r < 50);

            foreach (int item in query)
            {
                Console.WriteLine(item.ToString());
            }            
        }
        public static void Take_Print()        
        {
            int[] random = { 87, 2, 76, 90, 100, 65, 5, 22, 70 };
            IEnumerable<int> query = random.OrderBy(r => r).Take(4);

            foreach (int item in query)
            {
                Console.WriteLine(item.ToString());
            }            
        }


        public static void TakeWhile_Print()
        {
            int[] random = { 87, 2, 76, 90, 100, 65, 5, 22, 70 };
            IEnumerable<int> query = random.OrderByDescending(r => r).TakeWhile(c => c > 50);
            IEnumerable<int> query2 = random.OrderBy(r => r).TakeWhile(c => c > 50);// null
            foreach (int item in query2)
            {
                Console.WriteLine(item.ToString());
            }
        }
    }
posted @ 2010-04-17 22:09  CityWalker  阅读(335)  评论(0编辑  收藏  举报
天天来