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,097
  • 4
  • 41
  • 53
Nahum
  • 6,699
  • 11
  • 46
  • 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
  • 429,027
  • 67
  • 649
  • 891