Array.CopyTo Function

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I have an ArrayList that is an array of:

Class Address
Name as String
Age as Integer
End Class

How can I copy just the "Name" component to a single dimensional array?

Thanks,
Terry
 
Terry Olsen said:
I have an ArrayList that is an array of:

Class Address
Name as String
Age as Integer
End Class

How can I copy just the "Name" component to a single dimensional array?

You'll have to do it by hand:

Dim nameArray(myList.Count - 1) As String

For index As Integer = 0 To myList.Count - 1
nameArray(index) = DirectCast(myList.Item(index), Address).Name
Next index

Jeremy
 
Hi Terry,

You will have to loop through the arraylist, and copy each name to the new array
one by one.

Bill.
 
Here's what I have...

-------------------------------------------------
'ServerNames is the ArrayList that contains the UDT

Dim n As New clsNetwork

Dim nArray(n.ServerNames.Count - 1) As String

For Index As Integer = 0 To n.ServerNames.Count - 1

nArray(Index) = DirectCast(n.ServerNames.Item(Index), Address).Name

'"Address" in the line above is not valid.

Next

------------------------------------------------------------------------

Was I supposed to put "Address" in the code? Or was that meant to be
something else? And should this code work?

Thanks again!
 
Back
Top