LINQ C# Book

public void Linq77()
{
List products = GetProductList();

var categoryCounts =
from p in products
group p by p.Category into g
select new { Category = g.Key, ProductCount = g.Count() };

ObjectDumper.Write(categoryCounts
}
Result

Category=Beverages
Category=Condiments
Category=Produce
Category=Meat/Poultry
Category=Seafood
Category=Dairy Products
Category=Confections
Category=Grains/Cereals

ProductCount=12
ProductCount=12
ProductCount=5
ProductCount=6
ProductCount=12
ProductCount=10
ProductCount=13
ProductCount=7