I have a Point
struct:
public struct Point
{
public Point(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public double X;
public double Y;
public double Z;
}
then in the following code, I am creating an array of points and then dividing each points by a value 2
//Create a test array of Points
Point[] testPointArray = new Point[2];
testPointArray[0] = new Point(2, 4, 8);
testPointArray[1] = new Point(6, 12, 24);
//Divide by 2
testPointArray = testPointArray.Select(point => point = new Point(point.X / 2, point.Y / 2, point.Z / 2)).ToArray();
Question: In the above code, I am using the new
operator to replace each point with a newly created point. How can I directly make changes in the existing point (i.e. avoid creating new points)? I tried to do the following code, but the syntax is wrong:
testPointArray = testPointArray.Select(point =>
{
point.X = point.X / 2;
point.Y = point.Y / 2;
point.Z = point.Z / 2;
}).ToArray();