Split a List into smaller lists of N size

前端 未结 17 1864
后悔当初
后悔当初 2020-11-22 16:55

I am attempting to split a list into a series of smaller lists.

My Problem: My function to split lists doesn\'t split them into lists of the correct

17条回答
  •  广开言路
    2020-11-22 17:58

    public static IEnumerable> Batch(this IEnumerable items, int maxItems)
    {
        return items.Select((item, index) => new { item, index })
                    .GroupBy(x => x.index / maxItems)
                    .Select(g => g.Select(x => x.item));
    }
    

提交回复
热议问题