List<string> list = new List<string>();
for (int i = 1; i < 95; i++)
{
list.Add(i.ToString());
}
怎么样将list拆分成10个子集合?
for (int i = 1; i < 95; i++)
{
list.Add(i.ToString());
}
怎么样将list拆分成10个子集合?
解决方案
20
var result = list.Select(int.Parse).GroupBy(i => i % 10).Select(g => g.ToList()).ToList();
10
var res = Enumerable.Range(1, 95).Select((p, index) => new { index = index / 10, p = p.ToString() }).GroupBy(c => c.index);
30
List<List<string>> listGroup = new List<List<string>>(); int j = 10; for (int i = 0; i < list1.Count; i += 10) { List<string> cList = new List<string>(); cList = list1.Take(j).Skip(i).ToList(); j +=10; listGroup.Add(cList); }