我正在尝试迭代ObservableCollection分组,但我无法弄清楚foreach循环的正确语法。有什么想法吗?
ObservableCollection<SaleItem> list = new ObservableCollection<SaleItem>();
list.Add(new SaleItem("Beverage", "Pepsi", 3.99M));
list.Add(new SaleItem("Beverage", "Coke", 4.29M));
list.Add(new SaleItem("Clothing", "Jeans", 29.99M));
list.Add(new SaleItem("Clothing", "Shirt", 11.99M));
var foo = list.GroupBy(c => c.ItemType).AsEnumerable();
//Works, how do I iterate over it????
decimal sales = foo.FirstOrDefault().Sum(c => c.SalePrice);
// THIS IS THROWING A INVALID CAST
foreach (IEnumerable<IGrouping<string, Object>> obj in foo)
{
string f = "a";
}