How to get array upperbound value
Array.GetUpperBound Method (Int32) - Gets the index of the last element of the specified dimension in the array.
A zero-based dimension of the array whose upper bound needs to be determined.
The index of the last element of the specified dimension in the array, or -1 if the specified dimension is empty.
Note: - GetUpperBound(0) returns the last index in the first dimension of the array, and GetUpperBound(Rank - 1) returns the last index of the last dimension of the array.
Reference: Array UpperBound.xaml (5 KB)
I am not sure with the end array value. How to get the last array value.
Mate then specify problem with clear words
it is so simple to get last value . just use variable count of int type and assign array length to it-1.
then directly pass array count as an index to array name.
like arr_name(arr_name.length-1) // -1 because array indexing starts from 0 to length
Thanks for the post Aksh.
I have a Array variable with length of 10.
But all the array will not be occupied.
For example :
i am writing a loop which will store each value in a array variable. Sometimes it will end with 4 array values.
So i want to identify that last value.
So that is what i have mentioned in my first post. even you dont have to pass the length of array by using
Array.GetUpperBound Method (0) you will always get the actual length of array considering 0 as a starting index then use the returned value as your index with particular array to get the value.