I have 2 Lists of 2 different classes. We can call them Foo and Bar for this purpose. The List of Foos contains Bars that each Foo belongs to. The list of Bars contains all the Foos that the Bar belongs to.
I need a fast an efficient way of cycling through the two lists and adding each item to the other list.
I am currently using:
// Add the List of Zones to the Vehicles
foreach (Foo foo in Program.data.Foos.list)
{
foreach (Bar bar in Program.data.Bars.list)
{
bar.Foos.Add(foo);
foo.Bars.Add(bar);
}
}
However, for my set of data I have ~5000 Foos and ~5000 Bars. This is tacking ~3 seconds to itterate through the other most foreach loop and appears to be rather inefficient.
Are there any faster ways to accomplish this? Possibly with Linq? What would you guys recommend to speed this up some more? Or have I hit a brick wall in terms of speed?