So far, I’ve been using a KeyedCollection to create a large collection of objects (close to 1 million), each of which has a uint ID field as the collection’s key. That’s been great, but now I’m running into a problem as I expand the functionality: I have “override” records and need to replace any existing item with the same key by the new item. On average, perhaps 1 in 20 records might be overridden, conceivably even multiple times for the same record.
I don’t mind refactoring away from a KeyedCollection if necessary. What’s my best bet? Dictionary<>? The ids are not sequential, so straight indexing is out.
As with
Dictionaryyou should remove the item from the collection, alter/replace it and add it again.