Question

I have this dictoinary:

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

I wanted 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

Thanks in advance

Was it helpful?

Solution

Your syntax seems correct

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

what error you are getting?

OTHER TIPS

Just pass value to dictionary and it will return you a Key means if you dictionary is as follows:

Private Status As New Dictionary (Of String, String)
Status.Add("Y", "Married")
Status.Add("N", "Single")
Status.Add("X", "Its Complicated")

Below line of code will return you key

Dim Key As String = Status("Single")

Key = N

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top