Is there any .NET type that would represent a set of key-value pairs where each key will only be paired with a single value (like a regular Dictionary
), but also each value will only be paired with a single key? I've been thinking of this as an "invertible" dictionary because you could swap the keys with the values without any collisions. It shouldn't be hard to write such a class, and add methods like "TryGetKey" for a given value. However, I wanted to check if such a thing already existed somewhere, perhaps under a different name that I haven't thought of.
Also, considering the elegant answer to this question, would it be worthwhile for me to create a class to represent this invertible dictionary, when I could just as easily use LINQ to convert any dictionary to its value-key equivalent?