Retrieve Last Value In An Array

  • Thread starter Thread starter Andy Jones
  • Start date Start date
A

Andy Jones

I have a single dimension array that I need to retirevie the last value of
automatically can anyone tell me how to-do that?

I am reading into a combo box the array but whatever the last item is that
is read in I need to assign it to another variable and add 1 to it.

Thanks for any help.
While reader.Read()

cmbID.Items.Add(reader.Item(0))

End While
 
Andy Jones said:
I have a single dimension array that I need to retirevie the last value of
automatically can anyone tell me how to-do that?

I am reading into a combo box the array but whatever the last item is that
is read in I need to assign it to another variable and add 1 to it.

Thanks for any help.
While reader.Read()

cmbID.Items.Add(reader.Item(0))

End While

Are you sure it's an array?

In general:

lastitem = myarray(myarray.length - 1)


Armin
 
Are you sure it's an array?

In general:

lastitem = myarray(myarray.length - 1)


Armin

If you using VB2008 and .NET 3.5, then

Sub Main()
Dim arr() As Integer = {1, 2, 3, 4, 5}
' actually this will work with any type that
' implements IEnumerable(Of T)
Console.WriteLine(arr.Last())
End Sub

HTH
 
Back
Top