Hashtable with multiple values for single key

user557168 picture user557168 · Dec 29, 2010 · Viewed 51.8k times · Source

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.

Answer

Grace picture Grace · Dec 29, 2010

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);