vb.net 如何为字典数组 VB 中的每个值创建一个 For 循环?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17244058/
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 to create a For loop for each Value in Dictionary Array VB?
提问by Idle_Mind
I am working in VB script
我正在使用 VB 脚本
lets say this my dictionary content
让我们说这是我的字典内容
KbDictionary.Add("X", {"jump", "refract"})
KbDictionary.Add("Q", {"frag", "donar"})
KbDictionary.Add("Q", {"frag", "donar"})
how do i create a for loop for each value. like this
我如何为每个值创建一个 for 循环。像这样
for each st As String in KbDictionary.Valueswhich is the incorrect method i tried
for each st As String in KbDictionary.Values这是我试过的错误方法
回答by Idle_Mind
You're working with an Arrayof strings...
你正在处理一个字符串数组......
So just change:
所以只需更改:
For Each st As String In KbDictionary.Values
To:
到:
For Each st() As String In KbDictionary.Values
*Note the addition of parenthesis to indicate an array.
*注意添加括号以表示数组。
If you want to work with the Key and the Value at the same time then use a KeyValuePair like this:
如果您想同时使用 Key 和 Value,请使用如下所示的 KeyValuePair:
For Each kvp As KeyValuePair(Of String, String()) In KbDictionary
Debug.Print(kvp.Key & " --> " & String.Join(", ", kvp.Value))
Next

