Arrays vb.net存储多维数据的最简单方法
我想知道存储多维数据的最简单方法是什么 当我从数据库中检索记录时,我使用一个数组来存储一些信息,稍后我将像这样使用这些信息Arrays vb.net存储多维数据的最简单方法,arrays,vb.net,multidimensional-array,Arrays,Vb.net,Multidimensional Array,我想知道存储多维数据的最简单方法是什么 当我从数据库中检索记录时,我使用一个数组来存储一些信息,稍后我将像这样使用这些信息 rowCtr = 0 For Each dr As DataRow In dt.Rows md(rowCtr, 0) = dr("member_id").ToString md(rowCtr, 1) = dr("full_name").ToString md(rowCtr, 2) = dr("status").ToString md(rowC
rowCtr = 0
For Each dr As DataRow In dt.Rows
md(rowCtr, 0) = dr("member_id").ToString
md(rowCtr, 1) = dr("full_name").ToString
md(rowCtr, 2) = dr("status").ToString
md(rowCtr, 3) = dr("archived").ToString
...
rowCtr = rowCtr + 1
Next
md("443", "full_name") 'to get the full name
md("443", "status") 'to get the status
要访问特定成员的数据,我使用
'first i loop through the md array to get the array index (ind) of a member
'then, i can get the data of a member by using this
md(ind, 0) 'To get the id
md(ind, 1) 'To get the full name
这有点难,因为我总是需要知道并指定索引
我希望是这样
rowCtr = 0
For Each dr As DataRow In dt.Rows
md(rowCtr, 0) = dr("member_id").ToString
md(rowCtr, 1) = dr("full_name").ToString
md(rowCtr, 2) = dr("status").ToString
md(rowCtr, 3) = dr("archived").ToString
...
rowCtr = rowCtr + 1
Next
md("443", "full_name") 'to get the full name
md("443", "status") 'to get the status
其中443是一个成员id,我使用它作为第一个维度的键
我读过关于哈希表、字典、列表的书,但我似乎找不到一个在多维风格中使用它们的好例子
如果可能的话,我还希望长度是动态的,当我删除一个索引时,其余的将填充它的位置-
我还需要它有一个搜索方法来查找成员id是否已经在列表中
最简单的方法是什么?请回复。。谢谢不用麻烦将数据复制到数组-直接使用
数据表
:
Dim drMatch() As DataRow = dt.Select("member_id='443'")
If drMatch.GetUpperBound(0) >= 0 Then
MsgBox(drMatch(0).Item("full_name").ToString)
End If
如果您正在将来自不同来源的数据组装到数组中,我会定义一个新的内存
数据表来使用,而不是数组。不要麻烦将数据复制到数组中-直接使用数据表即可:
Dim drMatch() As DataRow = dt.Select("member_id='443'")
If drMatch.GetUpperBound(0) >= 0 Then
MsgBox(drMatch(0).Item("full_name").ToString)
End If
如果您正在将来自不同来源的数据组装到数组中,我会定义一个新的内存数据表来使用,而不是数组。不要麻烦将数据复制到数组中-直接使用数据表即可:
Dim drMatch() As DataRow = dt.Select("member_id='443'")
If drMatch.GetUpperBound(0) >= 0 Then
MsgBox(drMatch(0).Item("full_name").ToString)
End If
如果您正在将来自不同来源的数据组装到数组中,我会定义一个新的内存数据表来使用,而不是数组。不要麻烦将数据复制到数组中-直接使用数据表即可:
Dim drMatch() As DataRow = dt.Select("member_id='443'")
If drMatch.GetUpperBound(0) >= 0 Then
MsgBox(drMatch(0).Item("full_name").ToString)
End If
如果要将来自不同来源的数据组合到数组中,我会定义一个新的内存数据表来使用,而不是数组。如果必须将其保存为数组(不确定为什么),可以使用ENUM:
Enum Table1
Member_ID = 1
Full_Name = 2
Status = 3
archived = 4
End Enum
然后在阵列中可以执行以下操作:
md("443", Table1.Full_Name) 'to get the full name
md("443", Table1.Status) 'to get the status
如果必须将其另存为数组(不确定为什么),可以使用枚举:
Enum Table1
Member_ID = 1
Full_Name = 2
Status = 3
archived = 4
End Enum
然后在阵列中可以执行以下操作:
md("443", Table1.Full_Name) 'to get the full name
md("443", Table1.Status) 'to get the status
如果必须将其另存为数组(不确定为什么),可以使用枚举:
Enum Table1
Member_ID = 1
Full_Name = 2
Status = 3
archived = 4
End Enum
然后在阵列中可以执行以下操作:
md("443", Table1.Full_Name) 'to get the full name
md("443", Table1.Status) 'to get the status
如果必须将其另存为数组(不确定为什么),可以使用枚举:
Enum Table1
Member_ID = 1
Full_Name = 2
Status = 3
archived = 4
End Enum
然后在阵列中可以执行以下操作:
md("443", Table1.Full_Name) 'to get the full name
md("443", Table1.Status) 'to get the status