How to convert ArrayList to Array

N

None

Hi,

How can we convert ArrayList to Int[] (i.e., Integer Array).

If anybody knows the solution pls let me know.


Thanks and Regards,
Vinothkumar B
 
G

Greg Young

ArrayList.ToArray(type)

i.e.

int [] foo = (int []) ArrayList.ToArray(typeof(int []))

Cheers,

Greg Young
MVP C#
 
N

None

Hi,

Thanks for ur replay but when do this its throwing following
exception:

Exception:

At least one element in the source array could not be cast down to the
destination array type.
 
G

Greg Young

Yes the elements in the array have to be the type you are trying to make an
array of ..

for instance I can't add strings then ask for an array of integers ..

Cheers,

Greg Young
MVP - C#
 

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