public class Pager<T> where T : new() { private IEnumerable<T> _all; private IEnumerable<T> _current; public Pager() : this(0, 1000) { } public Pager(int pageIndex, int pageSize) : this(null, pageIndex, pageSize) { } public Pager(IEnumerable<T> items, int pageIndex = 0, int pageSize = 10) { PageIndex = pageIndex; PageSize = pageSize; if (items != null) { _all = items; var count = _all.Count(); PageCount = count % pageSize > 0 ? (count / pageSize + 1) : count / pageSize; } } public int PageIndex { get; set; } public int PageSize { get; private set; } public int PageCount { get; set; } public IEnumerable<T> Current { get { if (_all != null) _current = _all.Skip(PageIndex * PageSize).Take(PageSize); return _current; } set { _current = value; } } }
this pager supports dual methods, memory pagination or direct usage.