From: LP on
Hello,

What is C# equivalent of rediming an array and preserving exciting elements.
VB.NET syntax looks something like this:
ReDim Preserve myArray(5)
Thank you


From: Nicholas Paldino [.NET/C# MVP] on
LP,

You will want to use an ArrayList, which can be found in the
System.Collections namespace. When it returns a value, however, you will
have to cast that value to the type that is stored in it.

In .NET 2.0, you would use a List<T> instance (where T is the type you
want to store in the array), which can be found in the
System.Collections.Generic namespace.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp(a)spam.guard.caspershouse.com

"LP" <lp(a)a.com> wrote in message
news:eSn9y8FEFHA.1264(a)TK2MSFTNGP12.phx.gbl...
> Hello,
>
> What is C# equivalent of rediming an array and preserving exciting
> elements.
> VB.NET syntax looks something like this:
> ReDim Preserve myArray(5)
> Thank you
>
>


From: Herfried K. Wagner [MVP] on
"LP" <lp(a)a.com> schrieb:
> What is C# equivalent of rediming an array and preserving exciting
> elements.
> VB.NET syntax looks something like this:
> ReDim Preserve myArray(5)

First, create a new array of the desired size. Then use 'Array.Copy' to
copy the contents of the "old" array to the new array. After doing that,
assign the new array to the variable that is currently referencing the old
array.

If the number of items in an array changes frequently, consider using a more
dynamic datastructure, like an arraylist or one of the other collections
available in the 'System.Collections' namespace.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

From: Urs Vogel on
LP

There's nothing like it in C#, you have to build it own your own, if you
want to use plain arrays. But why don't you use the ArrayList class?

Urs

"LP" <lp(a)a.com> schrieb im Newsbeitrag
news:eSn9y8FEFHA.1264(a)TK2MSFTNGP12.phx.gbl...
> Hello,
>
> What is C# equivalent of rediming an array and preserving exciting
> elements.
> VB.NET syntax looks something like this:
> ReDim Preserve myArray(5)
> Thank you
>
>


From: LP on
Thank you all,

I would like to use ArrayList, but I am getting an array of strings from a
VB.NET class that someone else developed. I need to do further manipulation
on this array, add more elements and then pass it to another object as Array
of strings again that will store its data to SQL db.
I don't know if it makes sense to convert this Array to ArrayList and then
back to another Array.
The best option at this point (besides rewriting 2 objects) is to use
Array.Copy. Any other ideas?

"Urs Vogel" <uvogel(a)msn.com> wrote in message
news:OT6oGPGEFHA.512(a)TK2MSFTNGP15.phx.gbl...
> LP
>
> There's nothing like it in C#, you have to build it own your own, if you
> want to use plain arrays. But why don't you use the ArrayList class?
>
> Urs
>
> "LP" <lp(a)a.com> schrieb im Newsbeitrag
> news:eSn9y8FEFHA.1264(a)TK2MSFTNGP12.phx.gbl...
> > Hello,
> >
> > What is C# equivalent of rediming an array and preserving exciting
> > elements.
> > VB.NET syntax looks something like this:
> > ReDim Preserve myArray(5)
> > Thank you
> >
> >
>
>