Hashtable with multiple values for single key

后端 未结 11 1524
渐次进展
渐次进展 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:29

    You could use a dictionary.

    Actually, what you've just described is an ideal use for the Dictionary collection. It's supposed to contain key:value pairs, regardless of the type of value. By making the value its own class, you'll be able to extend it easily in the future, should the need arise.

    Sample code:

    class MappedValue
    {
        public string SomeString { get; set; }
        public bool SomeBool { get; set; }
    }
    
    Dictionary myList = new Dictionary;
    

提交回复
热议问题