I’ve been told that when you pass an Object to a method,
it’s passed “by value”. I made a little test to examine it:
Point p = new Point(1, 1);
Circle c = new Circle(p);
p.x = 999;
Console.WriteLine(c.p.x);
the code above prints “999”, but I thought the object is copied to the method
I’ve been told that if you’re not using “ref” (or “out”) the method get the value
of the object.
can someone make it clear to me?
thanks,
socksocket
Assuming
Pointis declared as class, notpitself is copied, the reference topis copied. So it’s still pass by value. You pass the value of a reference.When saying
Point p = new Point(1, 1);(and if point is a reference type), one might think it is a variable containing aPoint, but in fact it is a variable containing a reference to aPointthat is stored somewhere else.