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

it2022-05-09  18

无聊的测试程序。。

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()); }

转载于:https://www.cnblogs.com/loveasm/archive/2009/08/23/1552477.html

相关资源:linq实现分页

最新回复(0)