2016-07-11 7 views

答えて

2

あなたが探しているものを取得するためにGroupBy()Sum()とともにSelect()メソッドを使用することができ、あなたはこれらのStockオブジェクトのコレクションを持っていると仮定すると:

// This will group each of your elements by their product value and project each of these 
// groups to an object that stores the product and the sum of the stock properties for that 
// group. 
var totals = products.GroupBy(p => p.product) 
        .Select(p => new { Product = p.Key, Stock = p.Sum(x => x.stock) }) 
        .ToList(); 

あなたはできるsee a working example using your provided input here

+0

ありがとう、私のために働いた。 – Zebra

関連する問題