Re: Passing arrays ByVal vs ByRef
- From: "Schizoid Man" <schizoid_man@xxxxxxxxxx>
- Date: Fri, 3 Apr 2009 23:47:25 +0100
"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.
.
- Follow-Ups:
- Re: Passing arrays ByVal vs ByRef
- From: Tom Shelton
- Re: Passing arrays ByVal vs ByRef
- From: Cor Ligthert[MVP]
- Re: Passing arrays ByVal vs ByRef
- From: Scott M.
- Re: Passing arrays ByVal vs ByRef
- From: Scott M.
- Re: Passing arrays ByVal vs ByRef
- References:
- RE: Passing arrays ByVal vs ByRef
- From: David Anton
- Re: Passing arrays ByVal vs ByRef
- From: Scott M.
- RE: Passing arrays ByVal vs ByRef
- Prev by Date: Re: VB[2008] Newbie form question - removing standard menu when clicking on form icons
- Next by Date: Re: Passing arrays ByVal vs ByRef
- Previous by thread: Re: Passing arrays ByVal vs ByRef
- Next by thread: Re: Passing arrays ByVal vs ByRef
- Index(es):
Relevant Pages
|