ByVal and ByRef

Discussion in 'ASP .Net' started by Goncalo, Dec 4, 2003.

  1. Goncalo

    Goncalo Guest

    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
     
    Goncalo, Dec 4, 2003
    #1
    1. Advertising

  2. 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.

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio
    http://x-unity.miik.com.ua/teststudio.aspx
    Bring the power of unit testing to VS .NET IDE

    "Goncalo" <> wrote in message
    news:095a01c3ba4a$9d2f60e0$...
    > 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
     
    Dmitriy Lapshin [C# / .NET MVP], Dec 4, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Waz...
    Replies:
    0
    Views:
    421
    David Waz...
    Jul 4, 2003
  2. Iams

    Byval vs. byref

    Iams, Feb 24, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    4,814
  3. xamman
    Replies:
    1
    Views:
    347
    Marina Levit [MVP]
    Dec 22, 2006
  4. Rob Meade

    Byref / Byval?

    Rob Meade, Dec 28, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    787
    Rob Meade
    Dec 28, 2006
  5. ManicQin

    cTor argument byVal or byRef

    ManicQin, Aug 2, 2008, in forum: C++
    Replies:
    7
    Views:
    361
    James Kanze
    Aug 2, 2008
Loading...

Share This Page