Hashtable vs. Dictionary (key values)
-
Can a Hashtable accept two key values that are the same? if yes, then why can't a dictioanary accept two key values that are the same as it inherits from the hashtable class?
-
Can a Hashtable accept two key values that are the same? if yes, then why can't a dictioanary accept two key values that are the same as it inherits from the hashtable class?
Both will throw an exception when you do an
Add()
with the same key. You can change the value paired with a key with the indexer though.
-
Can a Hashtable accept two key values that are the same? if yes, then why can't a dictioanary accept two key values that are the same as it inherits from the hashtable class?
You have to write your own in order to have duplicates and there are a lot of valid reasons to have duplicates. A possible solution is to associate the key with a list or hash and inside the list have the objects with duplicate keys.
A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane