A MS help page about the difference between pass-by-value and pass-by-reference seems quite clear to me:
http://msdn.microsoft.com/en-us/library/8b0bdca4.aspx
However, a user comment at the end has confused me somewhat. It says (among other things) this:
if you don‘t use the ref or out keywords, then arguments to methods
are passed by value.
The comment seems quite wrong to me. Is it?
(I posted part of the comment out of context: Here’s the full comment:)
The text says: “… but when a class instance is passed, a reference
is passed. …” This is incorrect, as you can see in:C# Language specification Version 4.0 (a Microsoft free download)
5.1.4 Value parameters A parameter declared without a ref or out
modifier is a value parameter.So, in the example above, the class instance is passed by value, and
not by reference.
It is the full comment which is really confusing me… The class instance is passed by value and not by reference? Does that not imply that the instance bytes are pushed onto the stack?
The complete comment is misleading. The object’s reference is passed by value.