zoukankan      html  css  js  c++  java
  • Linq-分组统计

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication2
    {
        public class Plan
        {
            public string ProjectInfoId
            {
                get;
                set;
            }
    
            public string CommandInfoId
            {
                get;
                set;
            }
    
            public int value
            {
                get;
                set;
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                List<Plan> listPlan = new List<Plan>() {
                new Plan{ProjectInfoId="01", CommandInfoId="01001", value=0},
                new Plan{ProjectInfoId="01", CommandInfoId="01001", value=0},
                new Plan{ProjectInfoId="01", CommandInfoId="01002", value=0},
                new Plan{ProjectInfoId="02", CommandInfoId="02001", value=0},
                new Plan{ProjectInfoId="02", CommandInfoId="02002", value=1},
                new Plan{ProjectInfoId="02", CommandInfoId="02002", value=1},
                };
    
                var PlanGroups =
                    from p in listPlan
                    group p by
                    new
                    {
                        p.ProjectInfoId,
                        p.CommandInfoId
    
                    }
                        into g
                        let condition = g.Sum<Plan>(t => t.value)
                        where condition > 0
                        select new
                        {
                            g.Key,
                            NumProducts = condition            
                        };
              
    
                foreach (var group in PlanGroups)
                {
                    Console.WriteLine(string.Format("{0},{1}:{2}", group.Key.ProjectInfoId.ToString(), group.Key.CommandInfoId.ToString(), group.NumProducts));
                }
            }
        }
    }
  • 相关阅读:
    jquery总结
    Reporting Services子报表
    Reporting Services分组及Toggle
    Reporting Services报表钻取
    Reporting Services环境
    两种很有用的组件
    Reporting Services正确显示页码
    Reporting Services发布
    Java面试题
    BigInteger引申的一个访问权限控制解决方案
  • 原文地址:https://www.cnblogs.com/siso/p/3692493.html
Copyright © 2011-2022 走看看