I want to translate all points in a List<T>
. This works:
for (int i = 0; i <PolygonBase.Count; ++i)
{
PolygonBase[i] = PolygonBase[i] + MousePos;
}
But using List<T>.ForEach
doesn't:
PolygonBase.ForEach(v => v += MousePos);
Ideas?
I want to translate all points in a List<T>
. This works:
for (int i = 0; i <PolygonBase.Count; ++i)
{
PolygonBase[i] = PolygonBase[i] + MousePos;
}
But using List<T>.ForEach
doesn't:
PolygonBase.ForEach(v => v += MousePos);
Ideas?
Copyright © 2021 Jogjafile Inc.
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:To write back to the original value, use
ConvertAll
: