In the VB.NET world, there is the ReDim Preserve operation that lets you
dynamically resize an array while preserving it’s contents. Unfortunately,
here in the C# world, we do not have that option and have to use a method not
unlike what you found, that of creating a new array of the size we want,
copying the values from the old array to the new, and updating the reference
to point to the new array.
This is at least the case if you are using an actual array ([] style).
Another option you have is using the ArrayList class from System.Collections
which does incorporate the Add() and Remove() methods you are looking for,
however it internally pretty much does what was described above.
Brendan
"Brad" wrote:
I found an article that discussed dynamic allocation of an array but it seems
extremely overloaded in time requirements for function. The process is fine
if there's no data in it, but if there is an additional set of steps is
necessary that make it seem less than efficient:
tmp = Array.CreateInstance(...)
orig.CopyTo(tmp,0)
orig = tmp
I would have thought an Add/Remove method would have been provided and
solution would have been more efficient.
Help? Thoughts?
--
Brad Eck
<a href="http://www.sitesdynamic.com">SitesDynamic</a>
<a href="http://www.basketsetcetera.com">Baskets Etcetera</a>