I already read official MSDN doc and multiple SO question regarding Dictionary/Hashset and other unordered collections order issues. This question is a bit different - I'm looking for actual practical examples instead of theory
Conditions:
- a dictionary/hastable entry CAN ONLY BE ADDED
- a dictionary/hastable entry IS NEVER REMOVED (unless Cleared at beginning)
- a dictionary/hastable is operating with VALUE TYPES only
- a dictionary/hastable is never changed in any other way but Adding elements
- a dictionary/hastable always starts at 0 and index is preserved through simple code logic
- a dictionary key itself (the key name) is never changed manually
Code Sample:
Dictionary<int, int> test = new Dictionary<int, int>();
for (int i = 0; i <= 100000; i++)
{
test.Add(i,i);
}
var c = 0;
while (c < test.Count)
{
if (c != test.ElementAt(c).Key)
{
Console.WriteLine("Mismatch!");
break;
}
c++;
}
Console.WriteLine("Test passed!");
//Program takes a 2hrs walk, does things, occasionally reads-only values from existing "test" collection
for (int i = 0; i <= 500000; i++)
{
test[test.Count] = test.Count;
}
c = 0;
while (c < test.Count)
{
if (c != test.ElementAt(c).Key)
{
Console.WriteLine("Mismatch!");
break;
}
c++;
}
Console.WriteLine("Test 2 passed!");
//repeat some stuff
Question: UNDER THE GIVEN STRICT RULES ABOVE - has anyone actually encountered a case when this kind of Dictionary randomly changed order of its elements? We aren't talking about MT Concurrent Collection here and again, I'm not interested in theory answers, I've read them.
A single example when test.ElementAt(5).key
would return key
being 11
or 115
is what I'm looking for.