wonder223

static DataTable GetData()
{
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Quantity", typeof(int));
table.Rows.Add("a", 1);
table.Rows.Add("a", 2);
table.Rows.Add("b", 2);
table.Rows.Add("b", 2);
table.Rows.Add("c", 1);
table.Rows.Add("c", 2);
table.Rows.Add("c", 3);
table.Rows.Add("c", 4);
return table;
}

static void Main()
{
Console.WriteLine("1111");
DataTable otable = GetData();


var query = from d in otable.AsEnumerable()
group d by d.Field<string>("Name") into g
select new
{
c2 = g.Key,
c3=g.Count(),
c4 = g.Sum(t => t.Field<int>("Quantity"))
};
query.ToList().ForEach(q => Console.WriteLine("{0},{1},{2}", q.c2, q.c3,q.c4));

Console.ReadLine();
}

分类:

技术点:

相关文章:

  • 2021-03-31
  • 2021-12-01
  • 2021-12-11
  • 2021-08-23
  • 2021-09-13
  • 2021-10-02
  • 2021-03-31
  • 2021-12-11
猜你喜欢
  • 2021-05-23
  • 2021-12-01
  • 2021-08-02
  • 2021-10-02
  • 2022-01-01
  • 2021-12-01
相关资源
相似解决方案