我正在尋找某種方式可枚舉拆分爲使用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