は、私は、リストのリストを持っていると仮定します。与えられたリストから新しいリストを作成して、要素が以下の例のようになるようにしたい。要素が新しいリストにあるリストのリストから新しいリストを作成する方法は、代替順序ですか?
入力: -
List<List<int>> l = new List<List<int>>();
List<int> a = new List<int>();
a.Add(1);
a.Add(2);
a.Add(3);
a.Add(4);
List<int> b = new List<int>();
b.Add(11);
b.Add(12);
b.Add(13);
b.Add(14);
b.Add(15);
b.Add(16);
b.Add(17);
b.Add(18);
l.Add(a);
l.Add(b);
出力(リスト): -
1
11
2
12
3
13
4
14
15
16
と出力リストnot contain more than 10
要素をする必要があります。
私は現在、foreach inside while
を使用してこれを行っていますが、どうすればいいですか?LINQ
int loopCounter = 0,index=0;
List<int> o=new List<int>();
while(o.Count<10)
{
foreach(List<int> x in l)
{
if(o.Count<10)
o.Add(x[index]);
}
index++;
}
ありがとうございます。
使用[ 'ジップ()'](https://msdn.microsoft.com/en-us/library/dd267698(V = vs.110).aspxの)と '()' – Dido
ください@ Dido - zipにはリストが1つではなく他のアイテムは含まれません –
LINQを使用する必要がある理由はありますか? –