I was wondering if there was a built in type in C# that was like ‘Dictionary’ but where both TKey and TValue had to be unique.
For example::
d.Add(1, "1");
d.Add(2, "1"); // This would not be OK because "1" has already been used as a value.
I know this is kind of exotic, but it seems that since there are about a billion collection types in the BCL it might exist. Any ideas?
How about having Dictionary and HashSet/secondary reverse Dictionary – it will solve the issue and will perform better than checks on single Dictionary.
Something like this, wrapped as class: