Convert DataTable to Generic List in C#

后端 未结 9 1298
既然无缘
既然无缘 2020-12-01 01:28

Disclaimer: I know its asked at so many places at SO.
My query is a little different.

Coding Language: C# 3.5

I have a DataTable named cardsTable that

9条回答
  •  星月不相逢
    2020-12-01 02:04

    Just a little simplification. I don't use ItemArray:

    List list = tbl.AsEnumerable().Select(x => new Person
                        {
                            Id = (Int32) (x["Id"]),
                            Name = (string) (x["Name"] ?? ""),
                            LastName = (string) (x["LastName"] ?? "")
                        }).ToList();
    

提交回复
热议问题