Converting ArrayList to Array of user defined objects

  • Thread starter Thread starter Dylan Parry
  • Start date Start date
D

Dylan Parry

Hi,

I have an ArrayList that contains objects of type "Client", and I would
like to convert the ArrayList to a regular Array before returning it
from a method. I would like to return it as an Array of "Client" objects.

I have looked at ArrayList.ToArray(Type type) but I am unsure how to use
it to create an array of clients. Can anyone help me?

Thanks,
 
I have an ArrayList that contains objects of type "Client", and I would
like to convert the ArrayList to a regular Array before returning it
from a method. I would like to return it as an Array of "Client" objects.
I have looked at ArrayList.ToArray(Type type) but I am unsure how to use
it to create an array of clients. Can anyone help me?

Just call list.ToArray(typeof(Client)) and cast the result to Client[].

Jon
 
Using a pointed stick and pebbles, Jon Skeet scraped:
Just call list.ToArray(typeof(Client)) and cast the result to Client[].

Cheers for the *very* quick response. That was remarkably easy :)
 
Back
Top