'Liste .foreach ()' und Mutabilität
-
15-11-2019 - |
Frage
Ich möchte alle Punkte in einen generationspflichtigen GeneraDicetagcode übersetzen.Das funktioniert: generasacodicetagpre.
aber mit List<T>
nicht't:
generasacodicetagpre.
Ideen?
Lösung
Your current code is simply re-assigning the local variable v
to a new value - it doesn't refer back to the original value in the list. It's the equivalent of writing:
foreach(int v in PolygonBase)
{
v += MousePos;
}
To write back to the original value, use ConvertAll
:
PolygonBase.ConvertAll(v => v += MousePos);
Andere Tipps
ForEach is not mutable, it doesn't change the data structure in any way. Check out this threat. Using conditional lambda statements with a foreach Action on a list
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow