Vb.net - multidimensional list of arrays

I managed to create a list of individual dimensional arrays, but I can not understand the multilevel arraylist.

Here is what I am trying to do:

I have a database (mdb) with 5 columns that I want each row to be in a list of arrays.

In PHP, what I usually do is:

$ array [$ field1] = array ($ field2, $ field3, $ field4, $ field5);

How do I do the same in vb.net, so anytime I need to get an element for the specific to string1 that I could name?

For one dimension, I could do the following, but I cannot figure out how to add more fields to one line of the array:

Dim tmpArrayX As New ArrayList tmpArrayX.Add(field(0)) tmpArrayX.Add(field(1)) etc... 
+4
source share
2 answers

If you want to use an ArrayList , just add it to other ArrayList s.

Or you can use regular arrays like:

 Dim multiArray(2, 2) As String multiArray(0, 0) = "item1InRow1" multiArray(0, 1) = "item2InRow1" multiArray(1, 0) = "item1InRow2" multiArray(1, 1) = "item2InRow2" 

Although my personal preference would be to use List like:

 Dim multiList As New List(Of List(Of String)) multiList.Add(New List(Of String)) multiList.Add(New List(Of String)) multiList(0).Add("item1InRow1") multiList(0).Add("item2InRow1") multiList(1).Add("item1InRow2") multiList(1).Add("item2InRow2") 

Edit: how to find the line:

 Dim listIWant As List(Of String) = Nothing For Each l As List(Of String) In multiList If l.Contains("item1InRow2") Then listIWant = l Exit For End If Next 
+16
source

'This allows you to add lines on the fly .... Tested and works!

 Dim multiList As New List(Of List(Of String)) Dim ListRow As Integer = 0 For each record in some_source dim Country as string = record.country 'from some source dim Date as Date = record.Date 'from some source dim Venue as string = record.Venue 'from some source dim Attendance as string = record.Attendance 'from some source multiList.Add(New List(Of String)) multiList(ListRow).Add(Country) multiList(ListRow).Add(Date) multiList(ListRow).Add(Venue) multiList(ListRow).Add(Rating) multiList(ListRow).Add(Attendance) ListRow = ListRow + 1 next 
0
source

All Articles