我有一個問題... 我試圖投入字符串字典鍵的值的列表,如果containsvalue和的條件爲真:VB字典包含的值返回鍵
但是,這是不正確的:(
這裏是一個代碼:
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
而現在,名單必須具備兩個要素 - > 「第一」 和 「first1」
你能幫我?非常感謝!
但是你循環了整個詞典,它有2個元素,爲什麼只有一個結果? –
目前還不清楚哪些功能沒有按預期工作。 –