ArrayList to Array

  • Thread starter Thread starter Mathew Yeates
  • Start date Start date
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
 
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
 
duh. Nothing like learning a new language to make you feel stupid.
Thx Richard.

Mathew
 
Back
Top