Peter said:
No, not really. Only by those who conflate the two incorrectly are they
both referred to as "by ref".
The conflation comes from the limitation of two keywords for
more then two possible ways of passing a "thing".
If you think of a complex data type, that is implemented as
a reference type, a "class" in C#, and you have a entity of
this type, an "instance", and you want to pass it to a function,
then you have at least three theoretic options of passing it.
a) pass a reference to the reftype-variable, e.g. use the
same storage location as the caller.
Needs ref/out-keyword in C#.
b) pass a copy of the reftype-variable, e.g. use different storage,
that yet refers ("points") to the same memory.
default behavior in C#.
c) pass a copy of the data
not possible in C#/.NET for ref-types, but possible in native C++,
for classes, and default for value types/structs in C#.
a) and b) concur functionally insofar, that you deal with the same
memory, the same "data". They differ, as the other gentleman said,
in the way a change of the reference, e.g. which chunk of memory is
referenced, is returned. It is returned for a)
but swallowed for b) for obvious reasons.
It's a matter of definition, but the definition is specific and
well-known, and matches what David is describing.
Yes, as I said, David was completely right.
I was also right, though my wording was kind of misleading.
No, that's not why the name "reference type" was chosen. The name was
chosen because variables of that type always are a reference to an
instance of the object, rather than storing the value in the variable
itself.
The name choice has nothing to do with passing by reference.
Of course the word "reference" has a similar meaning in both contexts.
Both reference types and value types are passed by value by default. A
reference type variable is a reference, so the value passed is a
reference. But it's still passed by value.
Which functionally makes a big difference, though it's formally the
same, because what you copy is completely different for the different
types.
Christoph