using System.Collections.Generic;
public static void Main()
List<Customer> CustomerList = new List<Customer>();
CustomerList.Add( new Customer { ID = 1, Name = "One", GroupID = 1 } );
CustomerList.Add( new Customer { ID = 2, Name = "Two", GroupID = 1 } );
CustomerList.Add( new Customer { ID = 3, Name = "Three", GroupID = 2 } );
CustomerList.Add( new Customer { ID = 4, Name = "Four", GroupID = 1 } );
CustomerList.Add( new Customer { ID = 5, Name = "Five", GroupID = 3 } );
CustomerList.Add( new Customer { ID = 6, Name = "Six", GroupID = 3 } );
var groupedCustomerList = CustomerList.GroupBy(u => u.GroupID)
.Select(grp =>new { GroupID =grp.Key, CustomerList = grp.ToList()})
foreach(var l in groupedCustomerList)
Console.WriteLine("Group#"+l.GroupID);
foreach(Customer c in l.CustomerList)
Console.WriteLine(c.GroupID.ToString()+":"+c.Name);
public int ID { get; set; }
public string Name { get; set; }
public int GroupID { get; set; }