Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个未知大小的数组,我想将它分成小数组。
例如,733 项数组将变为 7 100 项数组和一个 33 项数组的列表。
List<List<T>> Split(List<T> list, uint sublistsize)
我可以编写一些代码来做到这一点,但是有内置的东西吗?
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(); }