using System.Collections.Generic;
public static void Main()
var products = new List<Stock>() {
new Stock(1,"product1",10),
new Stock(2,"product1",20),
new Stock(3,"product3",5)
var totals = products.GroupBy(p => p.product)
.Select(p => new { Product = p.Key, Total = p.Sum(x => x.stock)})
foreach(var total in totals)
Console.WriteLine("{0} : {1}",total.Product, total.Total);
public string product{get;set;}
public decimal stock{get;set;}
public Stock(int i, string p, decimal s)