Retrieve Last Value In An Array

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
 
A

Armin Zingler

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
 
T

Tom Shelton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top