- Dictionary求和
Dictionary<string, double> dic = new Dictionary<string, double>();
double dl = dic.Sum(it => it.Value);
2.DataTable 求和
string Sum = dtSum.Compute("sum(LDZMJ)", "true").ToString();
3.DataTable列不重复
DataView dv = dt.AsDataView();
DataTable dtnew = dv.ToTable(true, "DQNAME");
4.DataTable选择前N行
public static DataTable DtSelectTop(int TopItem, DataTable oDT, string sort)
{
if (oDT.Rows.Count < TopItem) return oDT;
DataView dv = oDT.AsDataView();
dv.Sort = sort;
DataTable dt1 = dv.ToTable(); ;
DataTable NewTable = dt1.Clone();
DataRow[] rows = dt1.Select("1=1");
for (int i = 0; i < TopItem; i++)
{
NewTable.ImportRow((DataRow)rows[i]);
}
return NewTable;
}