我正在尝试在visual basic中创建一个存储多个值的数组,我想在PHP中这样做:
$arr = array("1" => "one", "2" => "two");
然后循环:
foreach($arr as $a => $b) {
}
VB.net中的等价物是什么?
答案 0 :(得分:2)
对于像以下的PHP数组:
$arr = array("1" => "one", "2" => "two");
VB.Net等价物是Dictionary(Of String, String)
。
两个使用示例:
Dim dicA As New Dictionary(Of String, String)
dicA.Add("1", "one")
dicA.Add("2", "two")
For Each Item As String In dicA.Values
Console.WriteLine(String.Format("{0}", Item))
Next
此示例使用集合初始值设定项,并且更接近您的PHP:
Dim dicB As New Dictionary(Of String, String) From {{"1", "one"}, {"2", "two"}}
For Each Item As String In dicB.Values
Console.WriteLine(String.Format("{0}", Item))
Next