public int Id { get; set; }
public string Name { get; set; }
public string Manager { get; set; }
public int BuildingId { get; set; }
public static void Main()
Department[] departments =
new Department { Id = 1, Name = "Accounting", Manager = "User1", BuildingId = 15 },
new Department { Id = 2, Name = "Sales", Manager = "User2", BuildingId = 3 },
new Department { Id = 3, Name = "IT", Manager = "User3", BuildingId = 15 },
new Department { Id = 4, Name = "Marketing", Manager = "User4", BuildingId = 3 }
group d by d.BuildingId into dp
select new { sorted = dp.Key, Department = dp };
Console.WriteLine(string.Format("Output collection count: {0}", output.Count()));
Console.WriteLine(string.Format("Sorted property type: {0}", output.First().sorted.GetType()));
Console.WriteLine(string.Format("Department property type: {0}", output.First().Department.GetType()));
foreach (var department in output.First().Department)
Console.WriteLine(string.Format("department property type: {0}", department.GetType()));