Usually, when you create a Dictionary<Tkey, TValue> , you need to go first and add the k / v pairs by calling add in the dictionary itself.
I have a Dictionary<string, mycontainer> , where mycontainer is a container of other objects. I need to be able to quickly add things to mycontainer, so I thought that maybe I could overload the operator[] index to create mycontainer on the fly if it does not already exist, and then allows me to directly call it an add as such:
mydictionnary["SomeName"].Add(myobject); without explicitly switching to creating mycontainer every time a container with the specified name does not exist in the dictionary.
I was wondering if this is a good idea or should I explicitly create new mycontainer objects?
source share