string []のリストとしてコードで解析されるテーブルがあります(各string []は列です)。
Column1| Column2 | Column3
--------+---------+----------
0 | 1 | 8
3 | 2 | 3
5 | 2 | 8
まあ言ってみれば:
string[] column1 = { 0, 3, 5 }
string[] column2 = { 1, 2, 2 };
string[] column3 = { 8, 3, 8 };
List<string[]> table = new List<string[]>() { column1, column2, column3 };
Column3でグループ化された列(つまりColumn1)を選択し、Column3にそれぞれ異なる値を持つリストを作成したいと思います。つまり、Column1をcolumn3でグループ化し、Column3の異なる値ごとにColumnを作成します。
出力は次のようになります。
string[] result1 = { 3 }; // From column3[1] = 3
string[] result2 = { 0, 5 }; // From column3[0] = column3[2] = 8
これは、この投稿、これ、およびmsdnのSimple1の組み合わせです。column1とcolumn3を使用してオブジェクトを作成することを考えてから、次の投稿を行います。
Class Row { public Row(string row1, string row3); }
List<Row> rows = new List<Row>();
for(int i = 0; i < column1.Length; i++)
{ rows.Add(new Row(Column1[i], Column3[i])); }
var output = rows.GroupBy(row => row.row3).ToDictionary(grp => grp.Key, grp => grp.ToList());
しかし、このコードコードは少し醜いです。のようなものはありませんか
column3.selectmany(...).GroupBy(row => row.row3).ToDictionary(grp => grp.Key, grp => grp.ToList());
つまり、新しいクラスを作成してオブジェクトのリストを埋める必要のない式...また、出力として必要です
string[] result1 = { 3 }; // From column3[1] = 3
string[] result2 = { 0, 5 }; // From column3[0] = column3[2] = 8