What structure involving Key and Value pair should be adopted when both Key and Value are repeated?
Scenario:
I am generating an anonymous type in WPF this way
var result = Enum.GetValues(typeof(Key)).Cast<Key>()
.Select(x => new {Key = x, Value = (int)x});
I tried converting it to Dictionary using
.ToDictionary(Key => Key, Value => (int)Value);
OR
.ToDictionary(Key => (int)Key, Value => Value);
But in both cases it gives exception that An item with the same key has already been added. which means keys are repeated in both cases.
Now what structure should be adopted in this scenario? Should i go for KeyValuepair<int, Key>[] or anything other?
Personally I’d just stick with a
Dictionary<TKey, List<TValue>>but if you want a fancier interface you might want to write your ownMultiMapwrapper class for that.Of course, in neither case can you use
ToDictionarysince that uses the existing unique-key dictionary internally but you can write your ownToMultiMapextension method.