I am trying to convert Datatable to List using C# like this
public void GetList()
{
ds = // here my dataset;
List<MasterList> result = new List<MasterList>();
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dt in ds.Tables[0].Rows)
{
result.Add(new MasterList()
{
Name = Convert.ToString(dt["Name"]),
Address = Convert.ToString(dt["Address"]),
City = Convert.ToString(dt["City"])
});
}
}
}
this code is working fine, but I want to know easy way to convert Datatable to List and here used foreach loop.
so what's solution for this ?