0

I have an unknown size array and I want to fragment it to small sized arrays.

For example 733 items array will become list of 7 100 item arrays and one 33 item array.

List<List<T>> Split(List<T> list, uint sublistsize)

I can write some code to do this but is there something built in?

AlG
  • 14,697
  • 4
  • 41
  • 54
Nahum
  • 6,959
  • 12
  • 48
  • 69

1 Answers1

0
static List<List<T>> Split<T>(IEnumerable<T> list, int sublistsize)
{
    return list.Select((i, idx) => new { Item = i, Index = idx })
         .GroupBy(x => x.Index / sublistsize)
         .Select(g => g.Select(x => x.Item).ToList())
         .ToList();
}
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939