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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -