Files
Kg.SeaTime/Service/Application.Service.Pub/Extends/PageExtend.cs
2026-05-29 19:06:51 +08:00

27 lines
764 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Application.Service.Pub;
public class PageExtend
{
/// <summary>
/// List 通用分页
/// </summary>
/// <param name="list">数据源</param>
/// <param name="pageIndex">当前页码从1开始</param>
/// <param name="pageSize">每页条数</param>
/// <returns>当前页数据</returns>
public static List<T> GetPageList<T>(List<T> list, int pageIndex, int pageSize)
{
// 空值保护
if (list == null || list.Count == 0)
return new List<T>();
// 页码最小为 1
pageIndex = pageIndex < 1 ? 1 : pageIndex;
// 分页核心
return list
.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
.ToList();
}
}