Testing the effects of passing array references using ByVal and ByRef : Array Parameters « Collections « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Collections » Array Parameters 
8.3.3.Testing the effects of passing array references using ByVal and ByRef
Module Tester

   Sub Main()
      Dim As Integer

      Dim firstArray As Integer()
      Dim firstArrayCopy As Integer()

      firstArray = New Integer() {123}
      firstArrayCopy = firstArray

      For i = To firstArray.GetUpperBound(0)
         Console.Write(firstArray(i" ")
      Next

      FirstDouble(firstArray)

      For i = To firstArray.GetUpperBound(0)
         Console.Write(firstArray(i" ")
      Next

      If firstArray Is firstArrayCopy Then
         Console.WriteLine("The references are equal.")
      Else
         Console.WriteLine("The references are not equal.")
      End If

      Dim secondArray As Integer()
      Dim secondArrayCopy As Integer()

      secondArray = New Integer() {123}
      secondArrayCopy = secondArray

      For i = To secondArray.GetUpperBound(0)
         Console.Write(secondArray(i" ")
      Next

      SecondDouble(secondArray)

      For i = To secondArray.GetUpperBound(0)
         Console.Write(secondArray(i" ")
      Next

      If secondArray Is secondArrayCopy Then
         Console.WriteLine("The references are equal.")
      Else
         Console.WriteLine("The references are not equal.")
      End If

   End Sub ' Main

   Sub FirstDouble(ByVal array As Integer())
      Dim As Integer

      For i = To array.GetUpperBound(0)
         array(i*= 2
      Next

      array = New Integer() {111213}
   End Sub 

   Sub SecondDouble(ByRef array As Integer())
      Dim As Integer

      For i = To array.GetUpperBound(0)
         array(i*= 2
      Next

      array = New Integer() {111213}
   End Sub 

End Module
1 2 3 2 4 6 The references are equal.
1 2 3 11 12 13 The references are not equal.
8.3.Array Parameters
8.3.1.Pass array
8.3.2.Passing arrays and individual array elements to procedures
8.3.3.Testing the effects of passing array references using ByVal and ByRef
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.