I am trying to create an array in visual basic to store multiple values, i want to do it like in PHP:
$arr = array("1" => "one", "2" => "two");
then looping through:
foreach($arr as $a => $b) {
}
what would be the equivalent in VB.net?
For a PHP array like:
$arr = array("1" => "one", "2" => "two");
The VB.Net equivalent is a Dictionary(Of String, String).
Two examples of usage:
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
This example uses a collection initializer and is a bit closer to your 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
Dim values As Double() = {1, 2, 3, 4, 5, 6}Dim a = {{1, 2.0}, {3, 4}, {5, 6}, {7, 8}}except you might want aDictionaryif you want to do lookup