zoukankan      html  css  js  c++  java
  • Linq对列表进行分组,求和,排序

    1.分组之后形成一个新的类的列表(分组过程中求和),最后又进行了一次排序

      public List<StaticForestArea> GroupForestList(List<FeatWithBSM> ListBSM)
           {
               var res = ListBSM.GroupBy(x => x.LZ).Select(x =>
                    new StaticForestArea
                    {           
                        LZ = x.Key,
                        Area = x.Sum(t => (t.geometry as IArea).Area),
                    }).ToList();
               res = (from x in res
                      orderby (x.Area) descending
                      select x).ToList();
               return res;
           }   
    
          public class StaticForestArea
           {
             public  string LZ { get; set; }
             public double Area { get; set; }
           }   
    

      2.简单的根据面积进行排序

     public  class FeatWithBSM
        {
            public IFeature feature { get; set; }
            public IGeometry geometry { get; set; }
            public string BSM { get; set; }
            public string LZ { get; set; }
            public string ZDGN { get; set; }
            public string TreeCategory { get; set; }
            public double ZXJL { get; set; }
           }
        }
    public void OrderList(List<FeatWithBSM> ListBSM)
           {
               var res = (from x in ListBSM
                          orderby (x.geometry as IArea).Area descending
                          select x).ToList<FeatWithBSM>();
                    
              this.features= res;
               
           }
    

      3.对一个大列表根据标识码不同,分成一个个的小列表

     List<FeatWithBSM> featureList = searchFeatures("", layer);
    group1 = featureList.GroupBy(x => x.BSM).Select(x =>
                    new FeatureCate
                    {
                        BSM = x.Key,
                        features = x.ToList()
                    }).ToList();
    public  class FeatureCate
        {
          
           public List<FeatWithBSM> features;
           public string BSM;
           public double SumArea;
    
           public string  ZDGN_1="-";//主导功能
           public string ZYSZ_1;//主要树种
           public string LZ_1;//林种
           public double ZXJL_1;//总蓄积量
    }

      

  • 相关阅读:
    C版程序语法 (消除左递归)
    文法
    201506110248 实验报告
    组合数据类型
    UBUNTU四种版本的区别【转】
    MFC对话框程序屏蔽回车与ESC键,Tab键
    std::fstream打开中文路径名失败的问题原因、解决方法以及注意事项
    前进。。。。。。
    程序员学习能力提升三要素[转]
    java学习推荐资源
  • 原文地址:https://www.cnblogs.com/1521681359qqcom/p/13234193.html
Copyright © 2011-2022 走看看