Array first or last item command

Look at Array.GetLowerBound, Array.GetUpperBound and Array.Length in the help.
Always make your arrays zero based in .NET (first element has index 0, last element has index Length - 1).
 
Sorting according to array data integer

Can I use any build in method to sort an array according to its array data integer, for example swap the a(0) and a(1) if a(0) > a(1). Sorting from the minimum number until the maximum number.
 
Get Upper Bound question

I know we can use myArray.GetUpperBound(0) to get the size of the array, but I don't know what is the meaning of 0 within the bracket and can we change it to other values?
 
The parameter of the GetUpperBound method is de dimension of the Array you want the upper bound of. As you probably know, arrays can have more than one dimension. So yes, you can specify another value than zero. Beware though: the method throws an IndexOutOfRangeExeption if the value is less than 0 or greater than Rank - 1.
 
Note that GetUpperBound does not give you the size of the array. Length does that. GetUpperBound gives you the index of the last element withing the specifed dimension, as getLowerBound gives you the index of the first element. If you want the element at the first and last position then getting the indexes of those positions is a good start, wouldn't you say?
 
Back
Top