PC Review


Reply
Thread Tools Rate Thread

ArrayList.ToArray to string array question

 
 
Walker Moore
Guest
Posts: n/a
 
      17th Aug 2011
I have a method which adds strings to an ArrayList then on the final line
converts it to a string array (which it returns).

ArrayList results = new ArrayList();

... stuff ...

return (string[])results.ToArray(typeof(string));

Is this safe? I don't need to initialize the string[] array do I? I'm
assuming ArrayList.ToArray does that.
 
Reply With Quote
 
 
 
 
Walker Moore
Guest
Posts: n/a
 
      18th Aug 2011
On Wed, 17 Aug 2011 18:04:25 -0700, Peter Duniho wrote:
[..]
>
> Yes, it does. But you should be using "List<string>" instead of
> "ArrayList". Then you can just return "results.ToArray()".


Thank you Peter!
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList.ToArray question GB Microsoft C# .NET 4 30th Aug 2006 12:43 AM
ArrayList.toArray() --> int[] ChuckD_Duncan Microsoft Dot NET Framework 1 25th Aug 2005 09:04 PM
Problems with ArrayList::ToArray Dirk Microsoft VC .NET 2 1st Aug 2004 07:48 PM
ArrayList.ToArray() question Derrick Microsoft C# .NET 4 2nd Mar 2004 08:38 PM
Re: ArrayList ToArray issues Jay B. Harlow [MVP - Outlook] Microsoft VB .NET 32 27th Aug 2003 10:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 AM.