Customer customerOne = new Customer(\"John\", \"Doe\");
Customer customerTwo = new Customer(\"Super\", \"Man\");
Customer customerThree = new Customer(\"Crazy\", \"Guy\"
var groups = customers.GroupBy(c => c.LastName).Where(g => g.Skip(1).Any());
foreach(var group in groups) {
Console.WriteLine(group.Key);
foreach(var customer in group) {
Console.WriteLine("\t" + customer.FirstName);
}
}
Output:
Doe
John
Jane
Man
Super
Bat
You can flatten the resulting sequence of groups into one sequence with
var list = groups.SelectMany(g => g);