I am trying to understand when to use Dictionary vs ConcurrentDictionary because of an issue I had with one of the changes I made to a Dictionary.
I had this Dictionary
private static Dictionary<string, Side> _strategySides = null;
In the constructor, I am adding some keys and values to the Dictionary I created like this
_strategySides.Add("Combination", Side.Combo);
_strategySides.Add("Collar", Side.Collar);
This code was fine and had been running in all environments for a while now. When I added
_strategySides.Add("Diagonal", Side.Diagonal);
This code starts to break with exceptions “Index was outside the bounds of the array.” On the dictionary. Then I got into the concept of ConcurrentDictionary and its uses and that I needed to choose ConcurrentDictionary over Dictionary in my case since its a multi threaded application.
So my question to all you gurus is that why didn't it throw an exception all these days and it started when I added something to a dictionary. Any knowledge on this will be appreciated.