namespace Application.Service.Pub;
public class PageExtend
{
///
/// List 通用分页
///
/// 数据源
/// 当前页码(从1开始)
/// 每页条数
/// 当前页数据
public static List GetPageList(List list, int pageIndex, int pageSize)
{
// 空值保护
if (list == null || list.Count == 0)
return new List();
// 页码最小为 1
pageIndex = pageIndex < 1 ? 1 : pageIndex;
// 分页核心
return list
.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
.ToList();
}
}