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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -