Undocumented dictionary function?
Dictionary<string, int> testdic = new Dictionary<string, int>();
testdic.Add("cat", 1);
testdic.Add("dog", 2);
testdic.Add("rat", 3);
testdic.Remove("cat");
testdic.Add("bob", 4);
Populate the dictionary and then remove the first item. Then add a new item. Bob then appears at position 1 and not at the end, so it looks like he remembers the deleted entries and reuses that memory space?
Is this documented anywhere because I can't see it on MSDN and gave me a day of grief because I assumed it would just keep adding to the end.
a source to share
It is not documented because it is just an implementation detail.
The implementation can change at any time. (And if you haven't read the source code carefully, you can't even be sure that your assumptions about the current implementation are accurate.)
A type Dictionary<K,V>
does not guarantee that its elements will be saved in any particular order, and you should not rely on any undocumented behavior that you observe. A dictionary is a map from keys to values, not an ordered list.
From MSDN documentation :
For enumeration ... [t] the order in which the elements are returned is undefined.
a source to share
The dictionary is not sorted, so you should never accept anything about the order of the elements.
The implementation is likely to be most efficient. This could mean that the current implementation demonstrates the behavior you are seeing. But this is not documented, so you shouldn't rely on it.
a source to share