using System.Collections.Generic;
public static void Main() {
new List<Pet>{ new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 },
new Pet { Name="Daisy", Age=4 } };
var query = pets.GroupBy(pet => pet.Age, pet => pet.Name);
foreach (var petGroup in query) {
Console.WriteLine(petGroup.Key);
foreach (var name in petGroup)
Console.WriteLine(" {0}", name);
public string Name { get; set; }
public int Age { get; set; }