我有一个DataRow。有没有办法将其转换为arraylist?我需要将它转换为arraylist因为我想将它传递给一个比较两个数组的函数,如果它们不相同则返回false。
foo(datarow, arraylist)
Public Function foo(ByVal arr1 as Arraylist, ByVal arr2 as ArrayList) as Boolean
Compare and return false if they are not the same
End Function
那么,我如何将datarow转换为arraylist以便我可以将它传递给该函数。
答案 0 :(得分:1)
我同意你应该只在必要时转换为ArrayList,但你当然可以。
Dim al As New ArrayList
Dim dt As New DataTable
dt.Columns.Add("f")
dt.Columns.Add("n")
Dim dr As DataRow
dr = dt.NewRow
dr.Item(0) = "First"
dr.Item(1) = "Name"
dt.Rows.Add(dr)
For Each row As DataRow In dt.Rows
For Each column As DataColumn In dt.Columns
al.Add(row.Item(column.ColumnName))
Next
MessageBox.Show(al.Item(0).ToString & " " & al.Item(1).ToString)
Next