Alex Rivera | Logout

Adding elements to a C# array

Asked 2012-03-05T17:15:37.580
11

I would like to programmatically add or remove some elements to a string array in C#, but still keeping the items I had before, a bit like the VB function ReDim Preserve.

c#
Edit
Report

1 Answer

6

Don't use an array - use a generic List<T> which allows you to add items dynamically.

If this is not an option, you can use Array.Copy or Array.CopyTo to copy the array into a larger array.

answered 2012-03-05T17:17:15.867

Your Answer