views:

20

answers:

0

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";
        }

related questions