vb.net - multi-dimension array list

前端 未结 2 1323
死守一世寂寞
死守一世寂寞 2021-02-06 13:46

I\'ve managed to make some single dimension array lists but I can\'t figure out a multi dimension arraylist.

Here\'s what I\'m trying to do:

I have a database (m

2条回答
  •  走了就别回头了
    2021-02-06 14:14

    If you want to use ArrayList, just make it's items contain other ArrayLists.

    Or you could use normal arrays as:

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

    Though my personal preference would be to use List as:

    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 row:

    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
    

提交回复
热议问题