我有这个词:
Dim chardict As Dictionary(Of Char, Integer) = Nothing
chardict.Add("A", 0)
chardict.Add("B", 1)
我想做以下if语句,但我对语法有点困惑:
if chardict.containskey("A")
'display the value that corrosponds to the letter "A"
'in this case display the character 0
[some code]
end if
提前致谢
答案 0 :(得分:-1)
您的语法似乎正确
If dictionary.ContainsKey("A") Then
Do
End If
你得到了什么错误?
答案 1 :(得分:-1)
只需将值传递给字典,如果字典如下,它将返回一个Key表示:
Private Status As New Dictionary (Of String, String)
Status.Add("Y", "Married")
Status.Add("N", "Single")
Status.Add("X", "Its Complicated")
以下代码行将返回密钥
Dim Key As String = Status("Single")
Key = N