How do I access the key/value of a dictionary? I have this code:

 Try If keystrokeDictionary.ContainsKey(letter) Then keystrokeDictionary.Keys.Equals(letter) End If Catch ex As Exception MsgBox(ex.Message) End Try Return letter 

Letter is a single letter that gets passed in with just its string value. Then keystrokedictionary is a dictionary that the information looks like this:

{[65, 0]} {[66, 1]} {[67, 2]} 

Where the key is the first number and the value is the second number. Since my code isn't looking at the key/value right, it's not returning a letter, and therefore not working.

6

2 Answers

Try like this,Use item to get corresponding value

letter = " "; If keystrokeDictionary.ContainsKey(letter) Then letter = keystrokeDictionary.Item(letter) End If Return letter 

.Equals() is not an assignment operator, but a comparison function.

Try

letter = " "; If keystrokeDictionary.ContainsKey(letter) Then letter = keystrokeDictionary.Values(letter) End If Return letter 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.