zoukankan      html  css  js  c++  java
  • DataTable Group By或运算 Linq Aggregate的使用

     class Program
        {
            static void Main(string[] args)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Name", typeof(System.String));
                dt.Columns.Add("Value", typeof(System.Int32));
    
                dt.Rows.Add("07", 1);
                dt.Rows.Add("07", 2);
                dt.Rows.Add("07", 4);
                dt.Rows.Add("07", 8);
                dt.Rows.Add("07", 4);
    
                dt.Rows.Add("08", 2);
                dt.Rows.Add("08", 8);
                dt.Rows.Add("08", 16);
                dt.Rows.Add("08", 8);
                dt.Rows.Add("08", 16);
    
                var query = from t in dt.AsEnumerable()
                            group t by new { Name = t.Field<string>("Name") } into m
                            select new
                            {
                                Name = m.Key.Name,
                                Sum = m.Sum(n => n.Field<int>("Value")),
                                CustomerValue = m.Aggregate(0, (d, n) =>
                                {
                                    return d | n.Field<int>("Value");
                                })
                            };
    
                query.ToList().ForEach(p =>
                {
                    Console.WriteLine($"Name:{p.Name}	Sum:{p.Sum}	CustomerValue:{p.CustomerValue}");
                });
                Console.ReadKey();
            }
        }

    慎于行,敏于思!GGGGGG
  • 相关阅读:
    LightOJ
    Peter and Snow Blower
    Gena's Code
    nyoj139--我排第几个 (康拓展开)
    hdoj1394(归并排序)
    树状数组
    Poj 1113--Wall(凸集)
    hdoj1437 -- 天气情况
    hdoj1428 -- 漫步校园 (记忆化搜索)
    图像边缘检测
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/6816463.html
Copyright © 2011-2022 走看看