Convert DataTable to List

后端 未结 14 1822
挽巷
挽巷 2020-12-04 12:09

I have an strongly typed DataTable of type MyType, I\'d like convert it in a List.

How can I do this ?

Thanks.

14条回答
  •  青春惊慌失措
    2020-12-04 12:52

    List listName = dataTableName.AsEnumerable().Select(m => new MyType()
    {
       ID = m.Field("ID"),
       Description = m.Field("Description"),
       Balance = m.Field("Balance"),
    }).ToList()
    

提交回复
热议问题