What a confusing use of terms!
To clarify,
-
for a method
foo(int[] myArray)
, "passing a reference (object) by value" actually means "passing a copy of the object's address (reference)". The value of this 'copy', ie.myArray
, is initially the Address (reference) of the original object, meaning it points to the original object. Hence, any change to the content pointed to bymyArray
will affect the content of the original object.However, since the 'value' of
myArray
itself is a copy, any change to this 'value' will not affect the original object nor its contents. -
for a method
foo(ref int[] refArray)
, "passing a reference (object) by reference" means "passing the object's address (reference) itself (not a copy)". That meansrefArray
is actually the original address of the object itself, not a copy. Hence, any change to the 'value' ofrefArray
, or the content pointed to byrefArray
is a direct change on the original object itself.