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
How can I seek key of dictionary by index value?
提问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
回答by Steve Douglas
Dictionary.ElementAt(index) works for me. It returns the Key/Value pair at the specified index.
Dictionary.ElementAt(index) 对我有用。它返回指定索引处的键/值对。