Linq skip skipwhile take takewhile

一、Skip()跳过

  static void Main(string[] args)
        {
            //skip()跳过
            int[] nums = { 1,23,45,69,78,123,14,18,45,69};
            //跳过3条
            nums.Skip(3).ToList().ForEach(i=>Console.WriteLine(i));
        }

二、take()提取

  static void Main(string[] args)
        {
            //take()提取
            int[] nums = { 1,23,45,69,78,123,14,18,45,69};
            //提取3条
            nums.Take(3).ToList().ForEach(i=>Console.WriteLine(i));
        }

三、takeWhile()条件为假结束匹配

     static void Main(string[] args)
        {
            //takewhile()条件匹配如果为假结束匹配
            int[] nums = { 100,23,45,69,78,123,14,18,45,69};
            //提取大于40的
            nums.TakeWhile(i => i > 40).ToList().ForEach(i=>Console.WriteLine(i));
        }

四、skipwhile()条件为假结束匹配

        static void Main(string[] args)
        {
            //skipwhile()条件匹配如果为假结束匹配
            int[] nums = { 100,23,45,69,78,123,14,18,45,69};
            //跳过40的
            nums.SkipWhile(i => i > 40).ToList().ForEach(i=>Console.WriteLine(i));
        }

posted @ 2015-11-20 13:45  七秒钟得记忆  阅读(271)  评论(0编辑  收藏  举报