Possible Duplicate:
C# dictionary type with unique keys and values
I would like to make sure that a dictionary has unique keys AND values. Is there any way to add this kind of validation outside of building my own class? That is the only way I can think of accomplishing validation for values in a dictionary. But, maybe there is some attribute I could add that I cannot seem to find via google.
I am looking to use this dictionary with WPF bindings, if that helps, also.
Dictionary keys are unique, by definition. Ensuring dictionary values are unique is done the same way you’d check every array or collection member is unique.
.NET 3.5 introduces
HashSet<T>which speeds things up, assuming your TValue type implementsEquals(TValue).