I have a List with objects. Each object has an ID. I want to remove all the objects which their IDs appear in a given collection.
I know that in 3.5 there are functions such as RemoveAll that can facilitate the search and remove.
the function’s prototype is:
internal SomeObject removeFromMe(Dictionary<string, string> idsToRemoveAreTheKeys)
What’s the best way to remove from the list?
Thanks.
This checks each item in the list once, and performs a key lookup in the dictionary, so it’s roughly O(N) because key lookups are fast.
If you looped through the keys, you’d have to do a linear search through the list each time, which would require O(N*M), where M is the number of keys in the dictionary.