Using the skip and take pages, the linqskiptake pages
Static int Main (string [] args) {// number of entries per page const int pageSize = 2; // page 0 is the first data int pageNum = 0; string [] computer = {"apple", "Lenovo", "HP", "Thinkpad", "Samsung", "VIVO", "OPPO", "Huawei ", "Xiaomi", "Microsoft", "Shenzhou", "IBM"}; while (pageNum * pageSize <computer. length) {// page skip, take method var page = computer. skip (pageNum * pageSize ). take (pageSize); Console. writeLine ("output page {0} record", pageNum + 1); // output the content of each page foreach (var q in page) {Console. writeLine (q);} pageNum ++;} Console. readKey (); return 0; // if it is static void Main, an error is returned}
list = list.Skip(pageNum* pageSize).Take(pageSize).ToLlist = list.Skip(2 * 2).Take(2).ToList();
PageSize: the number of data entries on each page.
PageNum: indicates the number of pages. The correct expression is pageNum + 1. PageNum = 0, which is the first page. PageNum = 1, which is the second page.
Skip: indicates that the calculation starts from pageNum * pageSize + 1, and pageNum * pageSize data records exist.
Take: equal to the value of pageSize. It can also be expressed as an int type.
PageNum * pageSize = 4. There are four data entries in front. The content on page 5th is displayed starting from 3rd.