vb.net - 多维数组列表 [英] vb.net - multi-dimension array list
问题描述
我已经设法制作了一些单维数组列表,但我无法找出多维数组列表.
I've managed to make some single dimension array lists but I can't figure out a multi dimension arraylist.
这是我想要做的:
我有一个包含 5 列的数据库 (mdb),我希望每一行都在一个数组列表中.
I have a database (mdb) with 5 columns that I want each row to be in an array list.
在 PHP 中我通常会做的是:
In PHP what I'd typically do is:
$array[$field1] = array($field2,$field3,$field4,$field5);
$array[$field1] = array($field2,$field3,$field4,$field5);
我如何在 vb.net 中执行相同的操作,以便在需要为特定的 row1 获取项目时可以调用它?
How I do the same in vb.net so anytime I need to fetch an item for a specific for the row1 I could call it?
对于单个维度,我可以执行以下操作,但我不知道如何向单个数组行添加更多字段:
For a single dimension I could do the following, but I can't figure out how to add more fields to a single array row:
Dim tmpArrayX As New ArrayList
tmpArrayX.Add(field(0))
tmpArrayX.Add(field(1))
etc...
推荐答案
如果你想使用ArrayList
,只要让它的item包含其他ArrayList
即可.
If you want to use ArrayList
, just make it's items contain other ArrayList
s.
或者你可以使用普通数组:
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"
虽然我个人更喜欢使用 List
作为:
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")
如何查找行:
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
这篇关于vb.net - 多维数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!