views:

1287

answers:

2

Are there any built-in C# data structures that are like a hash table but requires both the Keys and the Values to be unique among each other? I basically want a way to look up my Key object in a table via a unique Value and vice-versa. Next to maintaining two hash tables or iterating over each key in the hash table (which is slow), I cannot think of a better way to implement this.

Is the fact that I even have this request a sign that I am designing something incorrectly in my code?

+7  A: 

It's not necessarily a design flaw, but there's nothing built into the framework. Fortunately, there was a very similar question recently, and I wrote an answer which should serve you well.

Jon Skeet
Looks to be exactly what I was looking for! Thank you.
Matthew Ruston
+3  A: 

Google Collections calls this a BiMap. Maybe you could port this to C#?

erickson