I have to work on some code that's using generic lists to store a collection of custom objects.
Then it does something like the following to check if a given object's in the collection and do something if so:
List<CustomObject> customObjects;
//fill up the list
List<CustomObject> anotherListofCustomObjects;
//fill it up
//...
foreach (CustomObject myCustomObject in customObjects)
{
if (anotherListofCustomObjects.Contains(myCustomObject))
{
//do stuff
}
}
Problem is is taking forever to process 7000 objects like that.
This is not my code - I am just trying to come up options to improve it - Looks to me it would be much faster to use a dictionary to get the stuff by key instead of looping through the whole collection like the above.
Suggestions?