ByVal and ByRef

  • Thread starter Thread starter Goncalo
  • Start date Start date
G

Goncalo

Hi.

Can you tell me what's the difference between ByVal and
ByRef in VB.Net.

I'm asking this 'cause i'm passing an object into a
function ByVal, then I change that object and when the
function terminates the original object is changed.

This kind of output is usual when passing objects ByRef,
right?

Thank's in advance
Goncalo
 
Hi,

For objects (that is, reference types) ByVal means that the function being
called cannot overwrite the *reference* to the object instance which is
actually passed in the parameter variable. But it does not prevent the
callee to alter properties on the instance.

ByRef, on the other hand, enables the callee to overwrite the reference
itself and therefore substitute the original object instance with another
one.
 
Back
Top