Using the skip and take pages, the linqskiptake pages

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.