c# - Get the index of each item in a loop -
i have datatable , doing operations on take result this:
var result = row in dtgraph.asenumerable() group row row.field<string>("campaign") grp select new { campaign = grp.key, count = grp.count(), sl = grp.sum(s => s.field<decimal>("inb.servicelevel")) }; i want loop on result
i tried these 2 ways:
first
for (int i=0;i< result.count(); i++){ { } but couldn't type result[i].count
second
foreach (var item in result) { }
your linq expression returns ienumerable, cannot accessed through indexer. why result[i] in first attempt not work.
the fix simple: convert ienumerable list:
var result = (from ... select new { ... }).tolist();
Comments
Post a Comment