LINQ はかなり新しく、拡張メソッドに頭を悩ませようとしています。私がやろうとしていること:
1) col1 (string)、col2 (double)、col3 (DateTime) の 3 つの列を持つテーブルを作成します。
table1.Rows.Add("string 1", 1, new DateTime(2009, 01, 01));
table1.Rows.Add("string 1", 2, new DateTime(2009, 02, 01));
table1.Rows.Add("string 1",3, new DateTime(2009, 03, 01));
table1.Rows.Add("string 1", 4, new DateTime(2009, 04, 01));
table1.Rows.Add("string 2",1, new DateTime(2009, 05, 01));
table1.Rows.Add("string 2", 1, new DateTime(2009, 06, 01));
table1.Rows.Add("string 2", 5, new DateTime(2009, 07, 01));
table1.Rows.Add("string 3", 6, new DateTime(2009, 08, 01));
2) 列 1 でグループ化する LINQ クエリを記述し、グループ化された行を double 値を返すメソッドに送信する必要があります。このようなもの
var query = from t in table1
group t by t.col1 into g
select new { r1 = g.Key, r2=mycalc(g))
3)拡張機能があります:
public static double Median(this IEnumerable<DataSet1.DataTable1Row> source)
{
//calc using the grouped row data and return a dobule
}
私はこれに少し取り組んでいますが、よくわかりません。誰か助けてくれませんか?