G
Gigs_
namespace WindowByRef
{
class Window
{
public Window(int x, int y)
{
this.x = x;
this.y = y;
}
protected int x;
protected int y;
public void Move(int x, int y)
{
this.x = x;
this.y = y;
}
public void ChangePos(ref int x, ref int y)
{
this.x += x;;
this.y += y;
x = this.x;
y = this.y;
}
}
class TestWindowByRef
{
public static void Main()
{
Window wnd = new Window(5, 5);
int x = 5;
int y = 5;
wnd.ChangePos(ref x, ref y);
Console.WriteLine("{0}, {1}", x, y);
x = -1; // i would expect that x here is 10 -1 not 5 -1 but its 5 -1 or x =
this.x; in ChangePos not affect outside
y = -1;
wnd.ChangePos(ref x, ref y);
Console.WriteLine("{0}, {1}", x, y);
}
}
}
can someone just explain me this
thx
{
class Window
{
public Window(int x, int y)
{
this.x = x;
this.y = y;
}
protected int x;
protected int y;
public void Move(int x, int y)
{
this.x = x;
this.y = y;
}
public void ChangePos(ref int x, ref int y)
{
this.x += x;;
this.y += y;
x = this.x;
y = this.y;
}
}
class TestWindowByRef
{
public static void Main()
{
Window wnd = new Window(5, 5);
int x = 5;
int y = 5;
wnd.ChangePos(ref x, ref y);
Console.WriteLine("{0}, {1}", x, y);
x = -1; // i would expect that x here is 10 -1 not 5 -1 but its 5 -1 or x =
this.x; in ChangePos not affect outside
y = -1;
wnd.ChangePos(ref x, ref y);
Console.WriteLine("{0}, {1}", x, y);
}
}
}
can someone just explain me this
thx