Possible Duplicate:
Which collection for storing unique strings?
I am currently using a Dictionary<string, bool> to store a list of unique identifiers. These identifiers do not need to have any data associated with them - I am just using the Dictionary to be able to quickly check for duplicates.
Since I only need keys, and no values, is a Dictionary the way to go here, or is there another collection I don't know about that would be better suited?
You can't add duplicate keys to hashtables, because hashtables by design can only contain unique keys. If you need to store duplicate key/value pairs, use arrays.
A HashMap or a HashSet isn't a Set, or a Collection either, but that doesn't mean it accepts duplicate keys. you can use Hashset nad for that u have to override hashcode() and equals() method. Actually a Map (whether it is a HashTable, HashMap or whatever) can have duplicate values, but not duplicate keys.
No. Since the number of possible keys is much greater than the size of the hash table, there must be two keys that map to the same index. Any set that contains those two keys will have a collision.
Each key can only have one value.
HashSet<T>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With