2

我有一个二维字符串数组,我需要根据某些条件将项目添加到该数组中。

Dim mainColumnsSummary(,) As String
mainColumnsSummary = { _
                     {"slNo", "#", "Number", "30", True, ""}, _
                     {"assessmentDate", "Assessment Date", "DateTime", "100", True, ""}, _
                     {"assetDescription", "Description and function of asset", "String", "100", True, ""}, _
                     {"assetScope", "Scope of assessment", "String", "100", True, ""}, _
                     {"assetHazards", "Hazard identification", "String", "100", True, ""} _
                  } if dtTable.rows.count>0 then
   ' I need to add dtTable.rows(x)("Question") to this array. where x should take values from 0 to dtTable.row.count-1

我怎样才能得到这个结果。请帮助我编写 vb.net 中的代码。

4

1 回答 1

0

.NET 数组是具有固定长度的数据结构。创建后, .Length 属性会告诉您数组中有多少元素,并且长度是恒定的。您不能添加到数组。

您需要查看 System.Collections.Generic.List(Of T)。

我的VB不是很好,但试试这样的:

Dim mainColumnsSummary As New List(Of String())

mainColumnsSummary.Add({"slNo", "#", "Number", "30", True, ""})

然后,您应该能够根据需要向此列表添加任意数量的“行”。

于 2012-05-19T10:08:34.400 回答