×

VB.Net Programs

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

By Nidhi Last Updated : November 11, 2024

Array.ConstrainedCopy() Method in VB.Net

The ConstrainedCopy() method is used to copy the elements of one array to another array.

Syntax

Sub ConstrainedCopy (ByVal source_arr() as object, 
    ByVal index1 as integer, 
    ByVal dest_arr() as object, 
    ByVal index2 as integer,
    Byval length as integer) 

Parameter(s)

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

Return Value

It does not return any value.

VB.Net code to demonstrate the example of Array.ConstrainedCopy() method

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

'VB.NET program to demonstrate the ConstrainedCopy() 
'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 3 elements of arr1 element to arr2 from index 0.
        Array.ConstrainedCopy(arr1, 2, arr2, 0, 3)

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

Output

Arr2 Array elements:
30 40 50 90 100
Press any key to continue . . .

Explanation

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 ConstrainedCopy() method of Array class, here we also specified the length to specify how many elements will be copied to the destination array.

VB.Net Array Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.