ObservableCollection 的分组和排序
我正在尝试迭代 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";
}
I am trying to iterate through a ObservableCollection grouping, but I cannot figure out the correct syntax for the foreach loop. Any thoughts?
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";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论