hehe, I suggest you have another cup of coffee
You keep saying the
same thing...
lemme give it a try this time
In C#, objects are passed by reference automatically. No
need to use the 'ref' keyword in front of them?
Objects aren't passed.. objects are on the heap.. if you have something
like :
MyClass foo = new MyClass();
You instantiate an object which is then stored in the heap.. the
reference-type variable 'foo' is stored on the stack and holds the
reference to this object. when you pass this variable onto a method like:
MyForm f = new MyForm(MyClass foo2)
you actually pass the value of foo (which is the reference to the actual
object in the heap) to foo2.. foo2 is then stored on the stack with the
passed reference as its value which was 'copied' accross. Now, foo and
foo2 both have access to the heap-allocated object. If foo2 were to
change the object in some way, foo will be able to see the change -
however, since foo2 is another variable on the stack, making changes to
foo2 itself will not affect foo. Consider this:
MyForm(MyClass foo2) {
foo2 = new MyClass();
// foo2, above, now holds a reference to a newly allocated object
// foo, however, was not affected
}
-Andre