using System.Collections.Generic;
public int Id { get; set; }
public int BaboCount { get; set; }
public override string ToString()
"Id: {0}, BaboCount: {1}",
public static void Main()
var scarletts = new List<Scarlett>
new Scarlett { Id = 1, BaboCount = 1, },
new Scarlett { Id = 2, BaboCount = 2, },
new Scarlett { Id = 3, BaboCount = 1, },
new Scarlett { Id = 4, BaboCount = 2, },
new Scarlett { Id = 5, BaboCount = 1, },
IEnumerable<IGrouping<int, Scarlett>> groupedScarletts = scarletts.GroupBy(s => s.BaboCount);
foreach (IGrouping<int, Scarlett> gromp in groupedScarletts)
foreach (Scarlett scarlett in gromp)
Console.WriteLine(scarlett);
ILookup<int, Scarlett> lookupScarletts = scarletts.ToLookup(s => s.BaboCount);
foreach (IGrouping<int, Scarlett> gromp in lookupScarletts)
foreach (Scarlett scarlett in gromp)
Console.WriteLine(scarlett);