asp.net - How retrieve value from string collections in c# -
i have collection defined by:
public class companymodel { public string compnname { get; set; } public string compnaddress { get; set; } public string compnkeyprocesses { get; set; } public string compnstandards { get; set; } }
then stored names , addresses collection data table:
list<companymodel> companies = new list<companymodel>(); for(int = 0; < dt.rows.count; i++) { companies.add(new companymodel { compnname = dt.rows[i]["companyname"].tostring(), compnaddress = dt.rows[i]["address"].tostring() }); }
my question how retrieve each compnname collection ? tried this
foreach (companymodel company in companies) { string compnyname = company.compnname;
but return me blank result.
the simplest option use linq, e.g.
var names = companies.select(c => c.compnname);
Comments
Post a Comment