c# - 'List<T>.ForEach()' and mutability -


i want translate points in list<t>. works:

for (int = 0; <polygonbase.count; ++i)  {     polygonbase[i] = polygonbase[i] + mousepos; } 

but using list<t>.foreach doesn't:

polygonbase.foreach(v => v += mousepos); 

ideas?

your current code re-assigning local variable v new value - doesn't refer original value in list. it's equivalent of writing:

foreach(int v in polygonbase) {     v += mousepos; } 

to write original value, use convertall:

polygonbase.convertall(v => v += mousepos); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -