Is it possible, and if so how, to loop though the results of a LINQ query?
Something like this:
var results= from a in dt.AsEnumerable()
where a.Field<int>("id") == i
select new
{
id= a.Field<int>("id"),
a= a.Field<double>("a"),
b = a.Field<double>("b")
};
IEnumerable<string> colNames = results.First().GetType().GetProperties()
.Select(p => p.Name);
string[] columns = colNames.ToArray();
int i = 0;
foreach (var row in results)
{
for (int i = 0; i < columns.Count(); i++)
{
string foobar = (string)row[columns[i]];
i++;
}
}
Essentially, i want to replicate the following sort of functionality:
DataRow dr = new DataRow();
string foobar = dr[columns[i];
Thanks all in advance.