Hashtable with multiple values for single key

后端 未结 11 1499
渐次进展
渐次进展 2021-02-13 13:36

I want to store multiple values in single key like:

HashTable obj = new HashTable();
obj.Add(\"1\", \"test\");
obj.Add(\"1\", \"Test1\");

Right

11条回答
  •  无人共我
    2021-02-13 14:20

    You can't use the same key in a Dictionary/Hashtable. I think you want to use a List for every key, for example (VB.NET):

    Dim dic As New Dictionary(Of String, List(Of String))
    Dim myValues As New List(Of String)
    myValues.Add("test")
    myValues.Add("Test1")
    dic.Add("1", myValues)
    

    C#:

    Dictionary> dic = new Dictionary>();
    List myValues = new List();
    myValues.Add("test");
    myValues.Add("Test1");
    dic.Add("1", myValues);
    

提交回复
热议问题