2012-03-21 58 views
1

我有一個字典與條目設置。我想得到與該值相對應的字母,並且我在編碼方面有點卡住。這是我到目前爲止的代碼:ContainsValue VB

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

If chardict.ContainsValue(1) then 
    Console.WriteLine(the letter that corrosponds to the value) 
end if 

Output: B 

在此先感謝

+1

聽起來像是你的詞典是倒退。 – 2012-03-21 16:30:34

回答

2

添加這個到您的IF語句:

Dim Value = (From t In chardict 
      Where t.Value = 1 
      Select t.Key 
     ) 

    Console.WriteLine(Value(0)) 
+0

Linq周圍的括號是不必要的。 – 2012-03-21 16:32:20