DataTable to List<object>

后端 未结 7 964
误落风尘
误落风尘 2020-12-03 09:05

How do I take a DataTable and convert it to a List?

I\'ve included some code below in both C# and VB.NET, the issue with both of these is that we create a new object

相关标签:
7条回答
  • 2020-12-03 09:38

    Do you want to reference the rows of the table? In that case you should use the DataTable.Rows property.

    Try this:

    notes.AddRange(table.Rows);
    

    If the table rows implement INote then this should work.

    Alternatively you could do as you did above:

    foreach (INote note in table.Rows)
    {
      notes.Add(note)
    }
    
    0 讨论(0)
提交回复
热议问题