16,554
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
static void Main(string[] args)
{
DataTable dt = GetDT();
//每页条数
int pageSize=3;
//总页数
int pageCount=(dt.Rows.Count%pageSize)==0?dt.Rows.Count/pageSize:dt.Rows.Count/pageSize+1;
//i相当于当前页
for (int i = 0; i < pageCount; i++)
{
//抓取每页数据
DataTable q= dt.AsEnumerable().Skip((i) * pageSize).Take(pageSize).CopyToDataTable();
//打印模拟数据
foreach (DataRow item in q.Rows)
{
Console.WriteLine("a:{0},b:{1},c:{2}", item["a"],item["b"],item["c"]);
}
Console.WriteLine("----------------模拟分页-----------------");
}
Console.ReadLine();
}
public static DataTable GetDT()
{
DataTable dt = new DataTable();
dt.Columns.Add("a");
dt.Columns.Add("b");
dt.Columns.Add("c");
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr["a"] = i;
dr["b"] = i + "b";
dr["c"] = i + "c";
dt.Rows.Add(dr);
}
return dt;
}