【发布时间】:2012-09-17 09:07:15
【问题描述】:
在 vb.net 如果我有HashTable,key 是整数并且值是list of integers,如何将整数附加到给定键的值,
我已经尝试过了,但每次我发现最后添加的整数,(列表只添加了最后一项)。
这是我的代码,其中dt 是DataTable 对象
Dim dt = report.getEvaluationReportByObjectiveGroupId(29)
Dim data As New Hashtable()
Dim dataEntry As DictionaryEntry
Dim res As String
For Each row As DataRow In dt.Rows
Dim strYear = row.Item("Year")
Dim strData = row.Item("EmpCount")
If data.ContainsKey(strYear) Then
Dim newCountArr As List(Of Int32) = DirectCast(data(strYear), List(Of Int32))
' newCountArr.AddRange(data(strYear))
newCountArr.Add(strData)
' data.Remove(strYear)
' data.Add(strYear, newCountArr)
Else
Dim countArr As New List(Of Integer)
countArr.Add(strData)
data.Add(strYear, countArr)
End If
' data.Add(strYear, strData)
Next row
【问题讨论】: