我需要從分組對象列表中檢索平均時間跨度,但不知道從哪裏開始。從組中獲取平均時間跨度
列表中的每個對象都有一個TimeSpan類型的屬性,而且我已將List按另一個屬性分組。現在我需要每個組的平均TimeSpan。
List<Item> Items = new List<Item>();
Item _item1 = new Item { Category = "A", Duration = _someTimeSpan1};
Item _item2 = new Item { Category = "B", Duration = _someTimeSpan2};
Item _item3 = new Item { Category = "A", Duration = _someTimeSpan3};
Items.Add(_item1);
Items.Add(_item2);
Items.Add(_item3);
var _groupedItems = Items.GroupBy(i => i.Category);
在上面的例子_item1和_item3是在類別分組,我需要持續時間的用於這兩個項目中屬於組中的平均值。
任何幫助表示讚賞。
你想出什麼辦法?他們爲什麼不工作? – Oded
正如我所說,我不知道從哪裏開始。儘管按類別對項目進行分組,但我不知道如何僅訪問單個組中的項目的「持續時間」屬性。 – Menase