Hey guys – I’m stuck with this problem and im just wondering what the best way to handle it is.
Foreach (var customer in CustomerList)
{
Foreach (var appointment in AppointmentList)
{
if(appointment.customerId == customer.id)
customer.appointments.add(appointment)
}
}
this is the simplest way I can think to do it but im not sure if it’s the most efficient!
Any help would be great-
Thanks.
You could perhaps pre-group the shorter list; this should give you better performance – I can’t find citations to the exact big-O ratings since MSDN doesn’t cite them, but it could be O(n + m) instead of O(n * m).
then you can use:
Or without LINQ (from comments):