Возможно, это 4 года спустя, но я надеюсь, что это кому-нибудь поможет позже.Как упоминалось ранее в посте, невозможно использовать тот же ключ для различных значений в Hashtable (ключ, значение).Хотя вы можете создать List или некоторый объект в качестве значения в паре ключ / значение HashTable.
//instantiate new Hashtable
Hashtable hashtable = new Hashtable();
//create a class that would represent a value in the HashTable
public class SomeObject
{
public string value1 { get; set;}
public string value2 { get; set;}
}
//create a List that would store our objects
List<SomeObject> list = new List<someObject>();
//add new items to the created list
list.Add(new SomeObject()
{
value1 = "test",
value2 = "test1"
});
list.Add(new SomeObject()
{
value1 = "secondObject_value1"
value2 = "secondObject_value2"
})
//add key/value pairs to the Hashtable.
hashTable.Add("1", list[0]);
hashTable.Add("2", list[1]);
Затем, чтобы получить эти данные:
//retrieve the value for the key "1"
SomeObject firstObj = (SomeObject)hashTable[1];
//retrieve the value for the key "2"
SomeObject secondObj = (SomeObject)hashTable[2];
Console.WriteLine("Values of the first object are: {0} and {1}",
firstObj.value1,firstObj.value2);
Console.WriteLine("Values of the second object are {0} and {1}",
secondObj.value1, secondObj.value2);
// output for the WriteLine:
Values of the first object are: test and test1
Values of the second object are secondObject_value1 and secondObject_value2