Re: VB-101: Passing Arrays ByVal vs ByRef
- From: "Herfried K. Wagner [MVP]" <hirf-spam-me-here@xxxxxx>
- Date: Tue, 24 May 2005 19:20:07 +0200
"John Pass" <JohnPass@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb:
You write: 'assigning a new array object to the paramater won't change the reference of the variable being passed to the method'.
Do you mean that for the code section of line 99? :
'array = New Integer() {11, 12, 13}'
That would mean that a new object is created rather than the old one's data
are overwritten.
Yes. You are creating a new array and assign it to the method's parameter. If the parameter is passed 'ByVal', the array passed to the method in the parameter is not changed, because you are assigning the new array to a temporary copy of the array pointer passed to the method.
\\\
Public Sub Foo1(ByVal Bla() As Integer)
Bla = New Integer() {10, 20}
End SubPublic Sub Foo2(ByRef Bla() As Integer)
Bla = New Integer() {10, 20}
End Sub
..
..
..
Dim a() As Integer = {1, 2}
Foo1(a)' 'a' still points to the array containing {1, 2}.Foo2(a)
' 'a' points to the array containing {10, 20}.
///--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
.
- References:
- VB-101: Passing Arrays ByVal vs ByRef
- From: John Pass
- Re: VB-101: Passing Arrays ByVal vs ByRef
- From: Herfried K. Wagner [MVP]
- Re: VB-101: Passing Arrays ByVal vs ByRef
- From: John Pass
- VB-101: Passing Arrays ByVal vs ByRef
- Prev by Date: Re: VB-101: Passing Arrays ByVal vs ByRef
- Next by Date: Re: VB-101: Passing Arrays ByVal vs ByRef
- Previous by thread: Re: VB-101: Passing Arrays ByVal vs ByRef
- Next by thread: Maximized window cannot be minimized
- Index(es):
Relevant Pages
|