拆分集合为n个部分的LINQ? [英] Split a collection into n parts with LINQ?
本文介绍了拆分集合为n个部分的LINQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个很好的方式来分割集合为N的部分与LINQ? 不一定即使当然
Is there a nice way to split a collection into 'n' parts with LINQ ? Not necessarily even of course
推荐答案
一个纯LINQ和最简单的解决方案是为下。
A pure linq and the simplest solution is as under.
static class LinqExtensions
{
public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> list, int parts)
{
int i = 0;
var splits = from item in list
group item by i++ % parts into part
select part.AsEnumerable();
return splits;
}
}
这篇关于拆分集合为n个部分的LINQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文