很早之前写的一个程序,有个地方临时用到了hashtable保存中间数据, 最近客户反应某个输出结果有个地方反了,如是我读取结果时的代码看了下,没发现问题
接下来查看数据库,也没发现问题,最后重新从头测试一次,发现在从Hashtable读取数据保存到数据库中时就搞反了,演示代码如下
代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hsh As New Hashtable
hsh.Add(1, "aaa")
hsh.Add(2, "bbb")
hsh.Add(3, "ccc")
Dim s As String = "开始"
For Each objDE As DictionaryEntry In hsh
s = s & "," & objDE.Value
Next
Button1.Text = s
End Sub
原以为上面的代码中 s的值会是= "开始,aaa,bbb,ccc" ,
而实际结果去是 = "开始,ccc,bbb,aaa", 为什么会是这样呢?