Reputation: 595
I have
DataTable dt;
DataRow[] drArray = dt.Select().ToArray();
My requirement is i want to convert drArray
as List<string[]>
or
Converting Datatable to List<string[]>
in a fastest way.
Upvotes: 5
Views: 30040
Reputation: 117037
I think this will get you what you want:
List<string[]> results =
dt.Select()
.Select(dr =>
dr.ItemArray
.Select(x => x.ToString())
.ToArray())
.ToList();
This only works if the items stored in dr.ItemArray
have overriden .ToString()
in a meaningful way. Luckily the primitive types do.
Upvotes: 10