ByVal and ByRef

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top