An object is an instance of class . The memory for the object and any items are stored in the heap. In general, this is called [ Reference Type][2] , which means that it is treated as a link (pointer) to a location.
Unlike a struct is a Value Type that is processed directly.
Passing a By Reference element ( ref keyword or out , as Reed points out) transfers a link (pointer) to the subject in question. This means that if you pass an object by reference, you pass a pointer to a pointer to an object in memory.
An object
arg (stack) -> oRef (heap) -> oData (heap)
This means that we can change the pointer to another location (i.e. a completely different object).
Passing an element By value means transferring the object itself. In the case of structure, all this is pushed onto the stack. In the case of an object, the link is passed on the stack. This means that when an object is transferred, the object can still be involved and its members change, but it cannot be completely replaced by another object.
arg (stack) -> oData (heap)
source share