Created
June 17, 2020 16:07
-
-
Save xrisdoc/3a279d64bedcd7bd5d1a3c93ef8b3552 to your computer and use it in GitHub Desktop.
Splits an IEnumerable object into multiple IEnumerable objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private IEnumerable<IEnumerable<T>> SplitIntoPages<T>(IEnumerable<T> items, int itemsPerPage) | |
{ | |
var pages = new List<List<T>>(); | |
int pageCount = (int)Math.Ceiling((items.Count() / (decimal)itemsPerPage)); | |
int skipCount = 0; | |
for (int i = 0; i < pageCount; i++) | |
{ | |
var subset = items.Skip(skipCount).Take(itemsPerPage).ToList(); | |
pages.Add(subset); | |
skipCount += itemsPerPage; | |
} | |
return pages; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment