【发布时间】:2012-12-08 10:59:21
【问题描述】:
我有问题... 如果 containsvalue 的条件为真,我试图将其放入字符串字典键值列表中:
但是,这是不正确的:(
这是一个代码:
Private listID As New List(Of String) ' declaration of list
Private dictionaryID As New Dictionary(Of String, Integer) ' declaration of dictionary
'put a keys and values to dictionary
dictionaryID.Add("first", 1)
dictionaryID.Add("second", 2)
dictionaryID.Add("first1", 1)
If dictionaryID.ContainsValue(1) Then ' if value of dictinary is 1
Dim pair As KeyValuePair(Of String, Integer)
listID.Clear()
For Each pair In dictionaryID
listID.Add(pair.Key)
Next
End If
现在,列表必须有两个元素... -> "first" 和 "first1"
你能帮帮我吗? 非常感谢!
【问题讨论】:
-
但是你正在遍历整个字典,它有 2 个元素,为什么结果只有一个?
-
不清楚什么没有按预期工作。
标签: vb.net dictionary key contains