c# - How to refer to the actual element in foreach? -


i used following code step through ienumerable.

ienumerable<thing> things = ...; foreach (thing thing in things)   thing = method(thing); 

the compiler disagrees since i'm referring thing iterating variable. of course, intend affect underlying object in list, instead. how do that?

for now, went work-around using numerated iteration there 2 issues there. one, it's not coding imho. besides that, requires me change things ienumerable ilist (or should using list?!), will bite in lower when things big.

//list<thing> things = ...; ilist<thing> things = ...; (int = 0; < things.count(); i++)   things[i] = method(things[i]); 

you can project sequence linq:

 var transformedthings = things.select(t => method(t)); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -