I have a dictionary where my value is a List. When I add keys, if the key exists I want to add another string to the value (List)? If the key doesn\'t exist then I create a
I'd wrap the dictionary in another class:
public class MyListDictionary
{
private Dictionary> internalDictionary = new Dictionary>();
public void Add(string key, string value)
{
if (this.internalDictionary.ContainsKey(key))
{
List list = this.internalDictionary[key];
if (list.Contains(value) == false)
{
list.Add(value);
}
}
else
{
List list = new List();
list.Add(value);
this.internalDictionary.Add(key, list);
}
}
}