Re: Passing arrays ByVal vs ByRef





"Scott M." <s-mar@xxxxxxxxxxxxx> wrote in message news:#T3vJ0JtJHA.4324@xxxxxxxxxxxxxxxxxxxxxxx
This is indeed correct.

When you pass something ByVal, you will get a copy, but most people assume you get a copy of the data, which is not always the case.

What you get a copy of depends on the type you are passing. If you pass a reference type (such as an Array), you get a copy of the reference (the variable pointer), not the type (the Array) and this explains why your original array is modified when you modify the passed parameter.

When you pass a value type ByVal, you get a copy of the value (the data).

-Scott

Thanks for the information, Scott. I was misled a bit, because the method I was invoking was declared as:
Public Shared Function(ByVal InputArray() as Double) as Double

So I just assumed that the array that I was passing was using pass-by-value. If I understand correctly, regardless of the usage of ByVal or ByRef, arrays will *always* be pass-by-reference?

Thanks.

.



Relevant Pages

  • rs232...
    ... Hello Scott and everyone else who will read this post. ... //immediatelly assigned to this array. ... // from the rs232 port), ... I thank Scott and all members of the news groups that have helped me on the ...
    (microsoft.public.vc.language)
  • Re: ByVal and ByRef in VB.Net
    ... Because although you are passing the array ByVal, ... the reference type, but instead you are passing a copy of the pointer to the ... > Private Sub TestArrayList ...
    (microsoft.public.dotnet.general)
  • Re: [Question:]How to split one file into 3/4 using fortran?
    ... "Gary L. Scott" wrote: ... I don't know how to open the array to store the ... > Now if you know the EXACT format (exact number of comments, ... > Liberty is a well armed sheep contesting the vote. ...
    (comp.lang.fortran)
  • Re: Passing arrays ByVal vs ByRef
    ... If you pass a reference type (such as an Array), you get a copy of the reference, not the type and this explains why your original array is modified when you modify the passed parameter. ... Thanks for the information, Scott. ... So I just assumed that the array that I was passing was using pass-by-value. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Passing arrays ByVal vs ByRef
    ... "Scott M." wrote in message ... If you pass a reference type (such as an Array), you get a copy of the reference, not the type and this explains why your original array is modified when you modify the passed parameter. ... So I just assumed that the array that I was passing was using pass-by-value. ...
    (microsoft.public.dotnet.languages.vb)