Converting ArrayList to Array of user defined objects

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,
 
J

Jon Skeet

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
 
D

Dylan Parry

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 :)
 

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