public class Product { public string Name { get; set; } public int YearOfProduction { get; set; } }
var products = new[] { new Product {Name = "Flashlight", YearOfProduction = 2009}, new Product {Name = "Nanobot", YearOfProduction = 2012}, new Product {Name = "Disintegrator", YearOfProduction = 2012} };
var grouped = from product in products group product by product.YearOfProduction;
foreach (var group in grouped) { Console.WriteLine("Total of {0} products produced in year {1}:", group.Count(), group.Key); foreach (var item in group) { Console.WriteLine(item.Name); } Console.WriteLine(); }
Show Comments (1)
Loading Comments. Please Wait...