Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the integer array
Here, we are going to demonstrate the integer array in VB.Net.
Submitted by Nidhi, on December 07, 2020 [Last updated : March 06, 2023]
Create an integer array in VB.Net
Here, we will create an array of integers and then read elements from the user, after that print the elements on the console screen.
Program/Source Code:
The source code to demonstrate the integer array is given below. The given program is compiled and executed successfully.
VB.Net code to create an integer array
'VB.Net program to demonstrate the integer array.
Module Module1
Sub Main()
Dim arr As Integer() = New Integer(5) {}
Dim i As Integer = 0
Console.WriteLine("Enter array elements: ")
For i = 0 To 4 Step 1
Console.Write("Element[{0}]: ", i)
arr(i) = Integer.Parse(Console.ReadLine())
Next
Console.WriteLine("Array elements are: ")
For i = 0 To 4 Step 1
Console.Write("{0} ", arr(i))
Next
Console.WriteLine()
End Sub
End Module
Output:
Enter array elements:
Element[0]: 10
Element[1]: 20
Element[2]: 30
Element[3]: 40
Element[4]: 50
Array elements are:
10 20 30 40 50
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 arr of five elements.
Console.WriteLine("Enter array elements: ")
For i = 0 To 4 Step 1
Console.Write("Element[{0}]: ", i)
arr(i) = Integer.Parse(Console.ReadLine())
Next
In the above code, we read the elements of the array from the user.
Console.WriteLine("Array elements are: ")
For i = 0 To 4 Step 1
Console.Write("{0} ", arr(i))
Next
Console.WriteLine()
In the above code, we print the elements on the console screen.
VB.Net Array Programs »