Point
is a struct (i.e. value type). You pass it by reference, but you then create copy of point instance in constructor of PointMover
by assigning it to point
field:
public void Set(ref Point p)
{
point = p; // here you create copy of passed point
}
Thus modifications of point
don't affect p
(because they represent different instances of structure).
Note: If Point
would be a reference type (i.e. class) then this assignment would copy a reference, and both variables would have references to same instance in heap.
In order to fix this behavior, you need to modify point which was passed by reference without creating copy. E.g.
public static void Move(ref Point point, int dX)
{
point.X += dX;
}
Usage:
PointMover.Move(ref point, 20);
Or you can simply use Point.Offset(int dx, int dy)
method.