DataTable分组求和

方法一:

            DataTable dt =newDataTable();
            dt.Columns.Add(
newDataColumn("C1",typeof(int)));
            dt.Columns.Add(
newDataColumn("C2",typeof(string)));
            dt.Columns.Add(
newDataColumn("C3",typeof(int)));
            dt.Rows.Add(
1,"a",30);
            dt.Rows.Add(
2,"a",40);
            dt.Rows.Add(
3,"b",50);
            dt.Rows.Add(
4,"b",60);
            dt.Rows.Add(
5,"a",70);
            Console.WriteLine(
"a总和:"+dt.Compute("sum(C3)","C2='a'"));
            Console.WriteLine(
"b总和:"+dt.Compute("sum(C3)","C2='b'"));
/*
输出:
a总和:140
b总和:110
*/
===============================================================================================

方法二:

            循环计算

上一篇:Android RecyclerView的StaggeredGridLayoutManager实现交错排列的子元素分组


下一篇:Android可折叠收缩伸展的Expandable分组RecyclerView:模型抽象和封装(二)