How to check if a Dictionary contains a given value?

You can use ContainsValue:

If myDictionary.ContainsValue("Two") Then
    debug.print("Exists")
End If

That’s all you need.


Complementing raed´s answer, you can also use ContainsKey to search for the keys instead of the values.

If myDictionary.ContainsKey(1) Then
    debug.print("Exists")
End If

This also works with string keys, like in the example:

[{"Chris", "Alive"};{"John", "Deceased"}]

If myDictionary.ContainsKey("Chris") Then
    debug.print("Chris Exists in dictionary")
End If

If myDictionary.ContainsValue("Alive") Then
    debug.print("There is someone alive in the dictionary")
End If

Tags:

Vb.Net