One dimensional Array in VB.NET
How to use the One dimensional array in VB.NET?
Explanation
One Dimensional Array
One dimensional array stores all the elements of an array in a single row starting with index 0 until the end of the array.
Example:
Module Module1
Sub Main()
Dim ary(4) As Integer
Dim j As Integer
Dim i As Integer
ary = New Integer() {1, 2, 2, 3}
For i = 0 To ary.GetUpperBound(0)
j = ary(i) + j
Next
System.Console.Write("The Sum of Array is::")
System.Console.WriteLine(j)
Console.ReadLine()
End Sub
End Module
Result:
The Sum of Array is:8
Description:
In the above example, one dimensional array of type Integer
ary is declared with four elements.
Using a loop with the starting value of '0' to upperbound value of the array got using the
GetBound(0), the sum of array is calculated.