Limit of list and datatable

Source: Internet
Author: User

Because list <t> or datatable is often grouped, it encapsulates
In fact, there is nothing, mainly because the impable should use the importrow Method

Public class othermanager <t>
{
/// <Summary>
/// Fragment the list
/// </Summary>
/// <Param name = "Source"> List of shards <t> </param>
/// <Param name = "pagesize"> page size of a Part </param>
/// <Returns> </returns>
Public static list <t> segement (list <t> source, int pagesize)
{
List <list <t> List = new list <t> ();

If (Source = NULL | source. Count = 0)
{
Return list;
}

Int totalrec = source. count;

Int totalpage = totalrec % pagesize = 0? Totalrec/pagesize: totalrec/pagesize + 1;

For (INT Index = 0; index <totalpage; index ++)
{
Int start = Index * pagesize;
List <t> TMP = new list <t> ();
If (Index = totalpage-1) // The last page, half page
{
For (int row = start; row <totalrec; row ++)
{
TMP. Add (source [row]);
}
}
Else // full page
{
For (int row = start; row <start + pagesize; row ++)
{
Tmp. Add (source [row]);
}
}
List. Add (tmp );
}
Return list;
}

/// <Summary>
/// Shard the DataTable
/// </Summary>
/// <Param name = "source"> DataTable to be split </param>
/// <Param name = "pageSize"> page size of a Part </param>
/// <Returns> </returns>
Public static List <DataTable> Segement (DataTable source, int pageSize)
{
List <DataTable> list = new List <DataTable> ();
If (source = null | source. Rows. Count = 0)
{
Return list;
}

Int totalrec = source. Rows. count;

Int totalpage = totalrec % pagesize = 0? Totalrec/pagesize: totalrec/pagesize + 1;

For (INT Index = 0; index <totalpage; index ++)
{
Int start = index * pageSize;
DataTable dt = new DataTable ();

If (index = totalPage-1) // The last page, half page
{
For (int row = start; row <totalRec; row ++)
{
Dt. ImportRow (source. Rows [row]);
}
}
Else // full page
{
For (int row = start; row <start + pageSize; row ++)
{
Dt. ImportRow (source. Rows [row]);
}
}
List. Add (dt );
}
Return list;
}

}

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.