Imports System
Public Class Example
Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
' Creates and initializes a new integer array and a new Object array.
Dim myIntArray() As Integer = {1, 2, 3, 4, 5}
Dim myObjArray() As Object = {26, 27, 28, 29, 30}
' Prints the initial values of both arrays.
outputBlock.Text &= String.Format("Initially,") & vbCrLf
outputBlock.Text &= "integer array:"
PrintValues(outputBlock, myIntArray)
outputBlock.Text &= "Object array: "
PrintValues(outputBlock, myObjArray)
' Copies the first two elements from the integer array to the Object array.
Array.Copy(myIntArray, myObjArray, 2)
' Prints the values of the modified arrays.
outputBlock.Text &= ControlChars.NewLine + "After copying the first two" _
+ " elements of the integer array to the Object array," & vbCrLf
outputBlock.Text &= "integer array:"
PrintValues(outputBlock, myIntArray)
outputBlock.Text &= "Object array: "
PrintValues(outputBlock, myObjArray)
' Copies the last two elements from the Object array to the integer array.
Array.Copy(myObjArray, myObjArray.GetUpperBound(0) - 1, myIntArray, _
myIntArray.GetUpperBound(0) - 1, 2)
' Prints the values of the modified arrays.
outputBlock.Text &= ControlChars.NewLine + "After copying the last two" _
+ " elements of the Object array to the integer array," & vbCrLf
outputBlock.Text &= "integer array:"
PrintValues(outputBlock, myIntArray)
outputBlock.Text &= "Object array: "
PrintValues(outputBlock, myObjArray)
End Sub
Public Overloads Shared Sub PrintValues(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal myArr() As Object)
Dim i As Object
For Each i In myArr
outputBlock.Text &= String.Format(ControlChars.Tab + "{0}", i)
Next i
outputBlock.Text &= vbCrLf
End Sub
Public Overloads Shared Sub PrintValues(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal myArr() As Integer)
Dim i As Integer
For Each i In myArr
outputBlock.Text &= String.Format(ControlChars.Tab + "{0}", i)
Next i
outputBlock.Text &= vbCrLf
End Sub
End Class
' This code produces the following output.
'
' Initially,
' integer array: 1 2 3 4 5
' Object array: 26 27 28 29 30
'
' After copying the first two elements of the integer array to the Object array,
' integer array: 1 2 3 4 5
' Object array: 1 2 28 29 30
'
' After copying the last two elements of the Object array to the integer array,
' integer array: 1 2 3 29 30
' Object array: 1 2 28 29 30