getting last value from array list

mcfly

Well-known member
Joined
Jun 15, 2009
Messages
54
Programming Experience
Beginner
hi there,

was just looking for info on why I can't seem to get the last value from an arraylist of integers, my code looks like this:



VB.NET:
            'sort items in array
            arrayListInfo.Sort()

            Dim i, num As Integer

            i = arrayListInfo.Count

            i = i - 1

            num = arrayListInfo.Item(i)

            MsgBox("Your number " & num)

I have sorted the arraylist so that the highest value is at the top, if I use

num = arrayListInfo.Item(i)

and give i a number like 5 then this works but it just appears to have a problem the last number for me...anyone any ideas...????
 
VB.NET:
Dim ar As New ArrayList
Dim i As Integer() = {1, 11, 2, 3, 5, 22, 3}
ar.AddRange(i)
ar.Sort()
Label1.Text = ar.Item(ar.Count - 1).ToString
Gets me "22".

Since I like List(Of T)...
VB.NET:
Dim ar As New List(Of Integer)
Dim i As Integer() = {1, 11, 2, 3, 5, 22, 3}
ar.AddRange(i)
ar.Sort()
Label1.Text = ar.Item(ar.Count - 1).ToString
 
Last edited:
Back
Top