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

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -