访问字典的键/值 [英] Accessing the key/value of a dictionary

查看:138
本文介绍了访问字典的键/值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问字典的键/值?我有以下代码:

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是一个仅包含其字符串值而传递的单个字母.然后keystrokedictionary是一个字典,其信息如下所示:

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.

推荐答案

.Equals()不是赋值运算符,而是比较函数.

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

尝试

letter = " ";

If keystrokeDictionary.ContainsKey(letter) Then
   letter = keystrokeDictionary.Values(letter)
End If

Return letter

这篇关于访问字典的键/值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆