public static class RectangleExtension
{
public static Rectangle Offseted(this Rectangle rect, int x, int y)
{
rect.X += x;
rect.Y += y;
return rect;
}
}
....
public void foo()
{
Rectangle rect;
rect = new Rectangle(0, 0, 20, 20);
Console.WriteLine("1: " + rect.X + "; " + rect.Y);
rect.Offseted(50, 50);
Console.WriteLine("2: " + rect.X + "; " + rect.Y);
rect = rect.Offseted(50, 50);
Console.WriteLine("3: " + rect.X + "; " + rect.Y);
}
输出结果:
1: 0; 0
2: 0; 0
3: 50; 50
我的期望结果:
1: 0; 0
2: 50; 50
为什么在第二步中rect.Offseted(50, 50)没有修改矩形的x和y值?
我需要对我的RectangleExtension方法进行何种修改才能得到期望的结果?