ArrayList to Array

M

Mathew Yeates

I'm baffled by something. I want to turn an ArrayList (which stores
strings) into an array of strings. I know I can use the ToArray method
and pass in a type. But I can't get the code right. Any help here? Am I
supposed to pass in a Type?

ArrayList myarr;
myarr.Add("foo");
myarr.Add("goo");
string[] mystrings= myarr.ToArray(??);

Mathew
 
R

Richard Blewett [DevelopMentor]

string[] strs = myArrayList.ToArray(typeof(string));

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I'm baffled by something. I want to turn an ArrayList (which stores
strings) into an array of strings. I know I can use the ToArray method
and pass in a type. But I can't get the code right. Any help here? Am I
supposed to pass in a Type?

ArrayList myarr;
myarr.Add("foo");
myarr.Add("goo");
string[] mystrings= myarr.ToArray(??);

Mathew
 
M

Mathew Yeates

duh. Nothing like learning a new language to make you feel stupid.
Thx Richard.

Mathew
 

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