2

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",
    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?

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

4 Comments

beat me to it by 30 seconds =-) (Note: you don't need to use the Add method, assigning a value to an undeclared key will create it)
ok how about if your datasets is coming from an access database, not by assigning values like you have here?
sounds like its time for a new question :)
you know i moved things around and it is doing what i needed to. thanks. vb.net is not my friend:-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.