I working on a project that contain a list inside the hashtable and list would automatic create depends on the key. For instance,

Hashtable hastable = new Hashtable()

//I want my hashtable look like this:
//hashtable contain(key, value);
//my value would a list
//if my key is "A" then it would create a new list for key A
//if my next key is B, then it would create a brand new list for Key B

By the way, my key is a string. How to automatic create a list depends on key? Thank you so much

Just check if the hashtable contains the key then create a list if it doesn't

if (hashtable.Contains(key) == false) {
    hashtable.Add(key, new List<someType>());
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.