class :
class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
List
List<Foo> lst = new List<Foo>();
Datatable :
DataTable dt = GetFromDb ()....
I want to fill lst
with records from dt
.
I've managed doing :
Array.ForEach(dt.AsEnumerable().ToArray(), y = > lst.Add(new Foo()
{
Id = int.Parse(y["id"].ToString()), Name = y["name"].ToString()
}));
question :
- Can't I do something else like
dt.AsEnumerable().Select(_ => fill lst )
?
I know that part of the select signature (in this case ) is Func<datarow,void>
which wont compile
But still , is there any other way of doing this besides the ugly way of mine ?