In C# everything is passed by reference by default. In C/C++ not.
Sorry, this is a little pet peeve of mine. Perhaps colloquially, it is
"passed by reference". However, using any sensible technical definition
of the term, C# passes everything by value by default, and the same for
Java, and C. Ex:
void foo(T x) { x = some_value; }
int main()
{ T y;
y = some_value_2;
foo(y);
assert(y == some_value_2);
}
In Java, C, C++, and C#, the assert will pass. This is the very
definition of pass by value. A function which passes by value and
modifies its argument will not have its change affect the caller's
object. Let's take a more Java-specific example:
static void foo(String x) { x = "x"; } public static void
main(String[] args) { String y;
y = "y";
foo(y);
assert(y.equals("y"));
}
In this example, changing the argument x inside the function foo does
not change the caller's argument, y. This is because in Java arguments
are passed by value. It's just that the value being passed is a pointer,
what Java annoying calls a "reference". The pointer is being passed by
value, so any manipulation of the pointed-to object will be visible to
the caller, but any manipulation of the passed-by-value object, the
pointer itself, will not be visible to the caller. This is fundamentally
different than pass by reference:
void foo(int & x) { x = 1; }
int main()
{ int y;
y = 2;
assert(y == 2);
foo(y);
assert(y == 1);
}
In this case, both asserts will pass. The function foo when it modifies
its argument, x, that change actually modifies the caller's value.
This a very anal, but important type. Sometimes I see silly discussions
about Java when people write bad code, believing that Java has pass by
reference semantics, when it does not. It has pass by value semantics,
except that most values are "references", aka pointers. The same is true
for C#.