-
Notifications
You must be signed in to change notification settings - Fork 1
Grouping
Hendrik Bulens edited this page Jul 21, 2021
·
3 revisions
List<Customer> customers = new()
{
new Customer(1, "Jeff", "New York"),
new Customer(2, "Harvey", "Los Angeles"),
new Customer(3, "Donald", "New York"),
new Customer(4, "Megan", "Toronto"),
new Customer(5, "Frank", "New York"),
};
List<IGrouping<object, Customer>> groups = customers.GroupByMany(x => x.Name, x => x.Address).ToList();
Assert.IsTrue(groups.Count == 5);
int groupCount = groups.FirstOrDefault(x =>
{
object[] keys = x.Key as object[];
return (string)keys[0] == "Jeff" && (string)keys[1] == "New York";
})
.Count(); // Returns 1