using static System.Console;
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) {
foreach (var name in petGroup) WriteLine(" {0}", name);
public string Name { get; set; }
public int Age { get; set; }