【发布时间】:2013-09-05 06:33:45
【问题描述】:
我在这里所做的是将两列的表保存在数组列表和字典中。
Dim result As New ArrayList()
While dr.Read()
' Insert each column into a dictionary
Dim dict As New Dictionary(Of String, Object)
For count As Integer = 0 To (dr.FieldCount - 1)
dict.Add(dr.GetName(count), dr(count))
Next
' Add the dictionary to the ArrayList
result.Add(dict)
End While
………… 现在我想检查它,当它找到时 - 删除它。因为有很多数据,所以可以节省时间。我收到错误“集合已修改;枚举操作可能无法执行。”删除后进入下一步。我理解这个问题,但我该如何克服这个问题?如何将其转换为带删除的循环?
For Each dat As Dictionary(Of String, Object) In result
comp2 = dat("ID")
If comp2 = comp Then
advcode = advcode & "," & dat("ADVC")
found = True
firstattempt = False
result.Remove(dat)
Else
If found And Not firstattempt Then Exit For
End If
Next
【问题讨论】:
标签: vb.net for-loop dictionary arraylist