How to use GetUpperBound() and GetLowerBound() methods to get the upper and lower bound of an array in VB.NET

2 Answers

0 votes
Module Module1

    Sub Main()

        Dim arr() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

        Dim upper As Integer = arr.GetUpperBound(0)
        Dim lower As Integer = arr.GetLowerBound(0)
        Console.WriteLine("index from: {0} to: {1}", lower, upper)

    End Sub

End Module

' run:
' 
' index from: 0 to: 9

 



answered Apr 25, 2016 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim arr2D(,) As Integer = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}, {13, 14}}

        For i As Integer = 0 To arr2D.Rank - 1
            Console.WriteLine("Dimension {0}: index from {1} to {2}",
                              i, arr2D.GetLowerBound(i),
                              arr2D.GetUpperBound(i))
        Next

    End Sub

End Module

' run:
' 
' Dimension 0: index from 0 to 6
' Dimension 1: index from 0 To 1

 



answered Apr 25, 2016 by avibootz

Related questions

1 answer 187 views
187 views asked Aug 28, 2020 by avibootz
1 answer 213 views
1 answer 211 views
1 answer 115 views
...