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

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -