Search code examples
vb.netdictionarycontainskey

How to find values in dictionary in VB


I have this dictionary:

Dim chardict As Dictionary(Of Char, Integer) = Nothing
chardict.Add("A", 0)
chardict.Add("B", 1)

I want to do the following if statement but I am a bit stuck on the syntax:

if chardict.containskey("A")
    'display the value that corrosponds to the letter "A"
    'in this case display the character 0
    [some code]
end if

Solution

  • Your syntax seems correct

    If dictionary.ContainsKey("A") Then
        Do
    End If
    

    what error you are getting?