I want to store multiple values in single key like:
HashTable obj = new HashTable();
obj.Add("1", "test");
obj.Add("1", "Test1");
Right now this throws an error.
The array can have any number of values. And, each key can have an array with a different number of values.
You cant do that, All the keys in the Hash map or Hash Table should be unique.
In Hashtable, key must be unique. Duplicate keys are not allowed.
Dictionary is a generic type and returns an error if you try to find a key which is not there. The Dictionary collection is faster than Hashtable because there is no boxing and unboxing.
you can put your test,test1,test2,...
in a table and then put this table in a Hashtable as a value for the key which will be the same for all them.
For example try something like this:
List<string> list = new List<string>();
list.Add("test");
list.Add("test1");
and then:
HashTable obj = new HashTable();
obj.Add("1", list);
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