我正在System.Collections.Generic.Dictionary集合中添加一些值并将其删除。当我尝试添加之后,收款顺序与最初的不一样。
我的代码:
System.Collections.Generic.Dictionary<int, string> xx = new System.Collections.Generic.Dictionary<int, string>();
xx.Add(1, "1");
xx.Add(2, "1");
xx.Add(4, "1");
xx.Add(3, "1");
xx.Add(5, "1");
xx.Remove(1);
xx.Remove(2);
xx.Remove(4);
xx.Remove(3);
xx.Remove(5);
xx.Add(1, "1");
xx.Add(2, "1");
xx.Add(3, "1");
xx.Add(4, "1");
xx.Add(6, "1");
xx.Add(5, "1");
第一组添加后的输出:
xx[0]= 1, 1
xx[1]= 2, 1
xx[3]= 4, 1
xx[4]= 3, 1
xx[5]= 5, 1
删除并添加后输出
xx[0]= 6, 1
xx[1]= 4, 1
xx[3]= 3, 1
xx[4]= 2, 1
xx[5]= 1, 1
xx[6]= 5, 1
谁能解释我为什么会这样?