Basically I'd like to make a Dictionary work with duplicate keys without going into custom comparer implementations. There is an idea of:
Dictionary<key, List<value>>
but it still has some overhead. I wish Dictionary had "AllowDuplicates".
Basically I'd like to make a Dictionary work with duplicate keys without going into custom comparer implementations. There is an idea of:
Dictionary<key, List<value>>
but it still has some overhead. I wish Dictionary had "AllowDuplicates".
Not in the Fx < 3.5.. You can implement one, obviously, with a Dictionary of IList objects. But then you have the encapsulation issue/responsibility.
If you're using .NET 3.5, use the Lookup class.
By definition, a Dictionary contains unique keys. Your example above is effectively a sort of two-dimensional keyed array, a structure I've used many times. Why would you want to have duplicate keys? If you did, how would the Dictionary uniquely address its members?
.NET 2.0: PowerCollections contains the OrderedMultiDictionary
.
“Why would you want to have duplicate keys? “
It is the sorted part of the collection I am lazy about.
I want to sort by things like voltage, amps or temp in my collection and return the interment identifier value i am storing for this sensor.
I'd like to iterate through the top most and lowest most values of these sensors and show the identifiers of some of the sensors I need to check out even if there happens to be some duplication. Use the index as a tiebreaker, or select one at random I don't care.