我有这个简单的数据表:
type (string) | cnt (int)
_____________________________________
aaa 1
aaa 2
aaa 10
bbb 1
bbb 1
我想生成1 个这样的匿名类型:
{
sumAAA= 13 , sumBBB=2 //13=1+2+10....
}
类似的东西:(伪代码)
var obj= dt.AsEnumerable().Select(f=> new { sumAAA =f.sumOfCntOfAaa , sumBBB =f.sumOfCntOfBbb });
有什么帮助吗?
编辑,这将帮助你
DataTable dt = new DataTable("myTable");
dt.Columns.Add("cnt", typeof (int));
dt.Columns.Add("type", typeof (string));
DataRow row = dt.NewRow();
row["cnt"] = 1;
row["type"] = "aaa";
dt.Rows.Add(row);
row = dt.NewRow();
row["cnt"] = 2;
row["type"] = "aaa";
dt.Rows.Add(row);
row = dt.NewRow();
row["cnt"] = 10;
row["type"] = "aaa";
dt.Rows.Add(row);
row = dt.NewRow();
row["cnt"] = 1;
row["type"] = "bbb";
dt.Rows.Add(row);
row = dt.NewRow();
row["cnt"] = 1;
row["type"] = "bbb";
dt.Rows.Add(row);