vb.net 如何通过索引值查找字典的键?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4473840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:12:24  来源:igfitidea点击:

How can I seek key of dictionary by index value?

vb.netexcel

提问by xbonez

How can I get the key of a dictionary by passing the index value?

如何通过传递索引值来获取字典的键?

I'm trying:

我想:

If rs.Fields("NM").Value = dictNM.key(0)

that is, I want it to compare to the first key in the dictionary

也就是说,我希望它与字典中的第一个键进行比较

but I get the error

但我得到了错误

Compile error: Invalid use of property

I tried googling, but to no avail. I'm hoping this is even possible.

我尝试谷歌搜索,但无济于事。我希望这甚至是可能的。

回答by pstrjds

You should be able to use the Keys property:

您应该能够使用 Keys 属性:

dictNM.Keys(0)

Edit:
One thing to keep in mind is that the order of the keys is unspecified, see MSDN

编辑:
要记住的一件事是未指定键的顺序,请参阅MSDN

回答by Steve Douglas

Dictionary.ElementAt(index) works for me. It returns the Key/Value pair at the specified index.

Dictionary.ElementAt(index) 对我有用。它返回指定索引处的键/值对。