转换数据表中列出< T>
问题描述:
我型的MyType
,我想将它转换在名单,其中的一个强类型的DataTable; MyType的>
。
I have an strongly typed DataTable of type MyType
, I'd like convert it in a List<MyType>
.
我怎样才能做到这一点?
How can I do this ?
感谢。
答
下面做它在一个单行:
dataTable.Rows.OfType<DataRow>()
.Select(dr => dr.Field<MyType>(columnName)).ToList();
[修改:添加引用 System.Data.DataSetExtensions
您的项目,如果这个不编译]
[Edit: Add a reference to System.Data.DataSetExtensions
to your project if this does not compile]