I know a one dimensional array in BV.net is created like:
Dim Parents As New Dictionary(Of Integer, String) From {
{100, "Parent1"},
{200, "Parent2"},
{300, "Parent3"}
}
That’s a dictionary – a mapping of unique keys to values – and not a one-dimensional array. If you just want to iterate over it (especially if you want to do so in order), a list of tuples (Tuple(Of Integer, String)) or KeyValuePairs is probably more appropriate:
Dim parents As New List(Of Tuple(Of Integer, String)) From {
Tuple.Create(100, "Parent1"),
Tuple.Create(200, "Parent2"),
Tuple.Create(300, "Parent3")
}
You can extend that into a three-item tuple to give them each children:
Dim parents As New List(Of Tuple(Of Integer, String, List(Of Tuple(Integer, String))) From {
Tuple.Create(100, "Parent1", New List(Of Tuple(Integer, String)) From { Tuple.Create(101, "Child1"), Tuple.Create(102, "Child2") }),
Tuple.Create(200, "Parent2", New List(Of Tuple(Integer, String)) From { Tuple.Create(201, "Child1") }),
…
}
and to iterate over it,
For Each parent In parents
Console.WriteLine("[{0}] {1}", parent.Item1, parent.Item2)
For Each child In parent.Item3
Console.WriteLine(" [{0}] {1}", child.Item1, child.Item2)
Next
Next
Those aren’t very descriptive names, though, and you can always just make your own classes.
Class Parent
Public Property Number As Integer
Public Property Name As String
Public Property Children As New List(Of Child)()
Public Sub New(number As String, name As String)
Me.Number = number
Me.Name = name
End Sub
End Class
Class Child
Public Property Number As Integer
Public Property Name As String
Public Sub New(number As String, name As String)
Me.Number = number
Me.Name = name
End Sub
End Class
Depending on how these are related, it might be appropriate for one to inherit from the other. Then, for convenience, you can make the parent enumerable; for even more convenience, you can give it an Add method, which will allow the From syntax to be used as well:
Class Parent
Implements IEnumerable(Of Child)
Public Property Number As Integer
Public Property Name As String
Public Property Children As New List(Of Child)()
Public Sub New(number As String, name As String)
Me.Number = number
Me.Name = name
End Sub
Public Sub Add(child As Child)
Me.Children.Add(child)
End Sub
Public Function GetEnumerator() As IEnumerator(Of Child) Implements IEnumerable(Of Child).GetEnumerator
Return Me.Children.GetEnumerator()
End Function
Private Function GetEnumerator_() As IEnumerator Implements IEnumerable.GetEnumerator
Return Me.GetEnumerator()
End Function
End Class
and:
Dim parents As New List(Of Parent) From {
New Parent(100, "Parent1") From {
New Child(101, "Child1"),
New Child(102, "Child2")
},
…
}
My syntax might not be quite right on these, but you get the idea.