.net - Is there a generic collection with a key/value pair where key can occur more than once? -
i want use generic collection dictionary
, dictionary
requires every key unique. have multiple values same "key", need generic collection allow that.
i realize makes key no longer key, don't know else call it.
several options consider:
- use
dictionary<tkey, list<tvalue>>
— keep list of values each key, not preventing duplicate values same key (i.e. duplicate pairs); - use
dictionary<tkey, hashset<tvalue>>
— keep set of value each key, preventing duplicate values same key; - use
list<keyvaluepair<tkey, tvalue>>
— keep list of pair, not preventing duplicate values same key.
note in latter case keyvaluepair
struct
, not class
, hence implies bit different handling.
the right option depends on actual use case.
Comments
Post a Comment