//每页条数 const int pageSize = 2; //页码 0也就是第一条 int pageNum = 0; //源数据 string[] names = { "1","2","3","4","5","6","7","8","9" }; while (pageNum * pageSize < names.Length) { //分页 var query = names.Skip(pageNum * pageSize).Take(pageSize); Console.WriteLine("输出第{0}页记录", pageNum + 1); //输出每页内容 foreach (var q in query) { Console.WriteLine(q); } pageNum++; }
Linq:使用Take和Skip实现分页或遍历
最新推荐文章于 2024-05-02 09:03:12 发布