DataTable to List<object>

后端 未结 7 986
误落风尘
误落风尘 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条回答
  •  猫巷女王i
    2020-12-03 09:31

    No, creating a list is not costly. Compared to creating the data table and fetching the data from the database, it's very cheap.

    You can make it even cheaper by creating the list after populating the table, so that you can set the initial capacity to the number of rows that you will put in it:

    IList notes = new List(table.Rows.Count);
    

提交回复
热议问题