如何将DataTable转换为泛型列表?目前,我正在使用:DataTable dt = CreateDataTableInSomeWay();List<DataRow> list = new List<DataRow>(); foreach (DataRow dr in dt.Rows){ list.Add(dr);}有更好的方法吗?
3 回答
烙印99
TA贡献1829条经验 获得超13个赞
DataTableExtensions.AsEnumerable
List<DataRow>
IEnumerable<DataRow>
Enumerable.ToList
:
IEnumerable<DataRow> sequence = dt.AsEnumerable();
using System.Linq;...List<DataRow> list = dt.AsEnumerable().ToList();
慕盖茨4494581
TA贡献1850条经验 获得超11个赞
List<Employee> emp = new List<Employee>(); //Maintaining DataTable on ViewState //For Demo onlyDataTable dt = ViewState["CurrentEmp"] as DataTable; //read data from DataTable //using lamdaexpressionemp = (from DataRow row in dt.Rows select new Employee { _FirstName = row["FirstName"].ToString(), _LastName = row["Last_Name"].ToString() }).ToList();
- 3 回答
- 0 关注
- 275 浏览
添加回答
举报
0/150
提交
取消