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("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", ); dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", );
dt.Rows.Add("", ); 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(, (d, n) =>
{
return d | n.Field<int>("Value");
})
}; query.ToList().ForEach(p =>
{
Console.WriteLine($"Name:{p.Name}\tSum:{p.Sum}\tCustomerValue:{p.CustomerValue}");
});
Console.ReadKey();
}
}