使用datatable中的值填充类的快速方法

时间:2016-05-26 14:45:17

标签: vb.net

我想知道是否更快获得这样的DataTable;

id  value1  value2
1   Hello   World
2   Foo     Bar
3   Test1   Test2
4   123     One
5   1       0

进入这样的课程;

Public Class MyObj
    Public ID As Int32
    Public value1 As String
    Public value2 As String

我目前有这个;

Dim myret As New List(Of MyObj)
If dt IsNot Nothing Then
        For value As Integer = 0 To dt.Rows.Count
            Dim newObjAs New MyObj With {.ID = dt.Rows(value)("ID"), .value1 = dt.Rows(value)("value1"), .value2 = dt.Rows(value)("value2")}
            myret.Add(newObj)
        Next
    End If

0 个答案:

没有答案