ADVERTISEMENT
ADVERTISEMENT

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

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

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) 

Parameters:

  • 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.

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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

© https://www.includehelp.com some rights reserved.