开发者

change this php array to vb.net

开发者 https://www.devze.com 2023-04-13 06:57 出处:网络
i am currently looping through this with vb.net and writing on the console: fruits orange fruits banana

i am currently looping through this with vb.net and writing on the console:

fruits orange 
fruits banana
fruits apple
numbers 1
numbers 2
numbers 3
numbers 4
numbers 5
numbers 6
etc...

however, i would like to store my values like this this:

array (
  "fruits"  => array (
    "a" => "orange",
    "b" => "banana",
    "c" => "apple"
  ),
  "numbers" => array (1,2,3,4,5,6),
  "holes"   => array (
         "first"开发者_JAVA百科,
    5 => "second",
         "third"
  )
);

then when i get this, i would like to loop through each

array (
  "fruit" => "orange",
  "b" => "banana",
  "c" => "apple"
)

and check for certain values. i can do this easily in php, however, vb.net leaves me ARGH.

any ideas?


You can easily do it in vb.net too.

    Dim arr As Dictionary(Of String, Object) = New Dictionary(Of String, Object)

    arr.Add("fruits", {"orange", "banana", "apple"})
    arr.Add("numbers", {1, 2, 3, 4, 5, 6})
    arr.Add("holes", {"first", "second", "third"})

    For Each key As KeyValuePair(Of String, Object) In arr
        For Each obj As Object In key.Value
            Console.WriteLine(key.Key & " " & obj.ToString)
        Next
    Next

    Console.ReadLine()
0

精彩评论

暂无评论...
验证码 换一张
取 消