(LINQ)实现控制台中输出数据分页处理


无聊的测试程序。。

class ConsolePage
    {
        static void Main(string[] args)
        {

            List<int> a = new List<int>(){ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            PageOutput(a);
           
        }
       
       
        static void PageOutput(List<int> a)
        {
         
            //判断是否跳出循环
            bool goAgain = true;
            //"2" = 1 line for "Press any Key.." + 1 line for input cursor
            //numLine值不变,测试时,我将Console Windows调成 Width 80, Height 10
            //所有这里的numLine = 8
            int numLine = Console.WindowHeight - 2;

         
            int currentLine = 0;

            do
            {
                Console.Clear();
                var resultPage = a.Skip(currentLine).Take(numLine);
                foreach ( int i in resultPage )
                {
                    Console.WriteLine("{0}",i);
                }

                currentLine += numLine;

                Console.WriteLine("Press any Key..");
                ConsoleKey key = Console.ReadKey().Key;
                if (key == ConsoleKey.End)
                {
                    goAgain = false;
                    break;
                }
            }while( currentLine < a.Count());

}
posted @ 2009-08-23 19:20  Mangos  阅读(227)  评论(0)    收藏  举报