ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the use of the dynamic array

Here, we are going to learn how to demonstrate the use of the dynamic array in VB.Net?
Submitted by Nidhi, on December 11, 2020

Here, we will create an array and then redefine the size of the array using the "Redim" keyboard and assign more elements to the array.

Program/Source Code:

The source code to demonstrate the use of a dynamic array is given below. The given program is compiled and executed successfully.

'VB.Net program to demonstrate the use of the dynamic array.

Module Module1

    Sub Main()
        Dim intArray() As Integer
        ReDim intArray(5)

        intArray(0) = 10
        intArray(1) = 20
        intArray(2) = 30
        intArray(3) = 40
        intArray(4) = 50

        ReDim Preserve intArray(10)
        intArray(5) = 60
        intArray(6) = 70
        intArray(7) = 80
        intArray(8) = 90
        intArray(9) = 100

        Console.WriteLine("Array elements are: ")
        For i = 0 To 9
            Console.Write("{0} ", intArray(i))
        Next i
        Console.WriteLine()
    End Sub

End Module

Output:

Array elements are:
10 20 30 40 50 60 70 80 90 100
Press any key to continue . . . Array elements are:
10 20 30 40 50 60 70 80 90 100
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a function Main(). In the Main(), we created an array intArr of 5 elements and then we assigned the 5 elements to the array. After that, we redefined the size of the array using the ReDim and Preserve keyboard and then assigned some more elements to the array, and then print all elements of the array on the console screen.

VB.Net Array Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

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.