vb.net 存储多维数据的最简单方法
vb.net easiest way to store multidimensional data
我想知道存储多维数据的最简单方法是什么
当我从数据库中检索记录时,我使用一个数组来存储一些我稍后会用到的信息,就像这样
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
访问特定成员的数据,我使用这个
'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
有点难,因为我总是需要知道并指定索引
我想要这样
md("443", "full_name") 'to get the full name
md("443", "status") 'to get the status
其中443是会员id,我用它作为第一维的key
我读过哈希表、字典、列表 - 但我似乎找不到以多维样式使用它们的好例子
如果可能的话,我也希望长度是动态的,当我删除一个索引时,剩下的会填满它的位置-
我还需要它有一个搜索方法来查找 member_id 是否已经在列表中
最简单的方法是什么?请回复..谢谢
不要费心将数据复制到数组 - 只需直接使用 DataTable
:
Dim drMatch() As DataRow = dt.Select("member_id='443'")
If drMatch.GetUpperBound(0) >= 0 Then
MsgBox(drMatch(0).Item("full_name").ToString)
End If
如果您要将来自不同来源的数据组装到您的数组中,我会定义一个新的内存中 DataTable
来使用,而不是您的数组。
如果您必须将其保存为数组(不确定为什么要这样做),您可以使用 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
我想知道存储多维数据的最简单方法是什么
当我从数据库中检索记录时,我使用一个数组来存储一些我稍后会用到的信息,就像这样
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
访问特定成员的数据,我使用这个
'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
有点难,因为我总是需要知道并指定索引
我想要这样
md("443", "full_name") 'to get the full name
md("443", "status") 'to get the status
其中443是会员id,我用它作为第一维的key
我读过哈希表、字典、列表 - 但我似乎找不到以多维样式使用它们的好例子
如果可能的话,我也希望长度是动态的,当我删除一个索引时,剩下的会填满它的位置-
我还需要它有一个搜索方法来查找 member_id 是否已经在列表中
最简单的方法是什么?请回复..谢谢
不要费心将数据复制到数组 - 只需直接使用 DataTable
:
Dim drMatch() As DataRow = dt.Select("member_id='443'")
If drMatch.GetUpperBound(0) >= 0 Then
MsgBox(drMatch(0).Item("full_name").ToString)
End If
如果您要将来自不同来源的数据组装到您的数组中,我会定义一个新的内存中 DataTable
来使用,而不是您的数组。
如果您必须将其保存为数组(不确定为什么要这样做),您可以使用 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