zoukankan      html  css  js  c++  java
  • 【随记】关于List集合用Linq GroupBy分组过后的遍历小记

    List<LeaderKaoQin> lstLeader = new List<LeaderKaoQin>();//一个List集合
    IGrouping<string, LeaderKaoQin> IGroups = null;//由于 group 查询产生的 IGrouping<TKey,TElement> 对象实质上是列表的列表,所以需遍历2次

    List<IGrouping<string, LeaderKaoQin>>    deptLeaders = (from m in lstLeader group m by m.DepName into G orderby G.Key select G).ToList();

                //此处需要遍历2次

        double deptJB = 0;
                double deptZC = 0;
                for (int i = 0; i < deptLeaders.Count; i++)
                {
                    deptJB = 0;
                    deptZC = 0;
                    IGroups = deptLeaders[i];
                    sbDept.Append(string.Format("'{0}',", IGroups.Key));
          
                    foreach (var item in IGroups)
                    {
                        deptJB += item.Overtime;
                        deptZC += item.Normal;
                    }
                    sbDeptJB.Append(string.Format("{0},", deptJB.ToString("f2")));//保留2位小数
                    sbDeptZC.Append(string.Format("{0},", deptZC.ToString("f2")));
                }

    参考资料:

    https://msdn.microsoft.com/zh-cn/library/bb384063.aspx

  • 相关阅读:
    POJ2299--树状数组求逆序数
    每周总结
    2016湖南省赛--A题--2016
    ACM暑期训练总结
    jQuery实现拖动布局并将排序结果保存到数据库
    TP3.2整合kindeditor
    TP3.2整合uplodify文件上传
    Sublime Text3 使用
    ThinkPHP AJAX分页及JS缓存的应用
    Thinkphp分页类使用
  • 原文地址:https://www.cnblogs.com/xiesong/p/6071129.html
Copyright © 2011-2022 走看看