VB.Net program to demonstrate the Copy() method of Array class

Here, we are going to demonstrate the Copy() method of Array class in VB.Net.
Submitted by Nidhi, on January 19, 2021

The Copy() method is used to copy the elements of one array to another array from the starting index, here we use length to specify, how many elements get copied.


Sub Copy (ByVal source_arr() as object, 
    ByVal dest_arr() as object, 
    Byval length as integer) 


  • Source_arr: It is the specified source array.
  • Dest_arr: It is the specified destination array.
  • Length: It specifies how many elements to be copied.

Return Value: It does not return any value.

Program/Source Code:

The source code to demonstrate the Copy() method of the Array class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the Copy() 
'method of Array class.

Imports System

Module Module1
    Sub Main()
        Dim arr1() As Integer = {10, 20, 30, 40, 50}
        Dim arr2() As Integer = {60, 70, 80, 90, 100}

        'Copy elements of arr1 element to arr2 from 
        'starting to with specified length.
        Array.Copy(arr1, arr2, 4)

        Console.WriteLine("Arr2 Array elements:")
        For i = 0 To arr2.Length - 1 Step 1
            Console.Write(arr2(i) & " ")
    End Sub
End Module


Arr2 Array elements:
10 20 30 40 100
Press any key to continue . . .


In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.

In the Main() function, we created two arrays arr1 and arr2. Then we copy the elements of one integer array to another integer array using the Copy() method of Array class, here we used the length to specify how many elements will be copied to the destination array.

VB.Net Array Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.