我正在寻找某种方式可枚举拆分为使用LINQ,使得在输入每个连续的产品在未来的子表3个可枚举按顺序排列。所以输入
{"a", "b", "c", "d", "e", "f", "g", "h"}
会导致
{"a", "d", "g"}, {"b", "e", "h"}, {"c", "f"}
我已经做到了这样,但我敢肯定,必须有这种表达更优雅使用LINQ的方式。
var input = new List<string> {"a", "b", "c", "d", "e", "f", "g", "h"};
var list = new List<string>[3];
for (int i = 0; i < list.Length; i++)
list[i] = new List<string>();
int column = 0;
foreach (string letter in input)
{
list[column++].Add(letter);
if (column > 2) column = 0;
}
http://stackoverflow.com/questions/419019/split-list-into-sublists-with-linq – 2012-07-26 13:29:56
检查此链接,http://peshir.blogspot.nl/2011/02/example- of-c-lazy-functional.html – Maarten 2012-07-26 13:42:19
请不要编辑自动输入的重复问题链接。它是自动化的,如果问题重新打开,系统将无法删除它。而是在自动插入的明确标记的指示符下进行更改。 – BinaryMisfit 2012-07-27 11:35:20