Dear Friends,
How to create and populate multi-dimensional list?
How to create and populate multi-dimensional list?
Sub Test
Dim lst As List
lst.Initialize
Dim n(2) As Int
' populate the list
n(0) = 1
n(1) = 2
lst.Add( n )
Dim n(2) As Int ' new declaration, see below
n(0) = 3
n(1) = 4
lst.Add( n )
'...
' retrieve list elements
n = lst.Get(0)
Log( n(0) & "," & n(1)) ' prints "1,2"
n = lst.Get(1)
Log( n(0) & "," & n(1)) ' prints "3,4"
' change list content indirectly
n(0) = 5 ' this is still pointing to the object that was added to the list element lst.Get(1)
n(1) = 6
Dim m() As Int = lst.Get(1) ' create a new reference to n() from lst.Get(1)
Log( m(0) & "," & m(1)) ' prints 5,6
End Sub
?Unfortunately, there is no array notation like n( x, y, z ) and
Dim a,b,c,d,e As Int
a = 1
b = 2
c = 3
d = 4
e = 5
Dim n(a,b,c,d,e) As Int
Dim M As Map
M.Initialize
For Each I1 As String In Array As String("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
For Each I2 As String In Array As String("North", "South", "East", "Middle", "Gymnasium")
For Each I3 As String In Array As String("1", "2", "3", "Hall", "5", "6")
If Rnd(1, 100) <= 70 Then 'random 70% of rooms utilized
Dim I123 As String = I1&"_"&I2&"_"&I3
Dim NumStudents As Int = Rnd(5, 35) 'random data
M.Put(I123, NumStudents)
End If
Next
Next
Next
Log(M)
'there is a 30% chance this room won't have an entry, but let's give it a go anyway
Dim I123 As String = "Monday"&"_"&"North&"_"&5
Log(M.Get(I123))
Log(M.Get("Monday_North_5"))
How to create and populate multi-dimensional list?
+1Can you give an example?
I agree; sometimes (often?) you should use custom types or classes.So I am with Cableguy: an example would be useful