I have a datatable
which contains only one column and all items are strings. How can I convert this to a List<string>
using LINQ for example?
I Tried:
DataRow[] rows = dtusers.Select();
var qq = from RowCollection in rows
select new { UserCode = LibStatic.ToStr(RowCollection["UserCode"]) };
List<string> users = new List<string>();
users = qq.Cast<string>().ToList();
There is the easyway which always works:
foreach (DataRow dr in dtusers.Rows)
{
users.Add(dr[0].ToString());
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…