Create a new array of the right size, use Array.Copy to copy to give
the new array the same contents (where appropriate) as the old array,
and then discard the old array, using the new one instead.
Alternatively, use ArrayList from the start, where appropriate.
If you are doing this frequently, why then don't you use a strongly typed
collection instead?
This way, you have the convenience of ArrayList without the penalty of the
Copy at the end.
Just find a strongly typed collection generator (there are many) and point
it at your type (in this case, string)
Just a thought,
Rather than do the copying manually, you can use
ArrayList.ToArray(typeof(string)) instead.
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.