-2

What will be the C# equivalent of the following ReDim a(0 To i, 0 To 1) ?

I am trying to implement using it by Array.resize ... but it's not working.

apratik
  • 141
  • 2
  • 11

1 Answers1

5

Since you aren't using Preserve, this is just:

a = new SomeType[i,1];

More generally Array.Resize (which is akin to ReDim Preserve) only works on vectors (1-dimensional 0-based arrays); there is not an overload for multi-dimensional arrays. You can, however, simply create a new array and then copy the data from the old array to the new array in a loop. However, frankly if you are routinely resizing arrays, then something might be wrong in your code - maybe consider some kind of nested list; or since your second direction is always 0-1, either two separate arrays/lists, or a single array/list of a type with two members.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • +1 especially for suggesting replacing with "two separate arrays/lists, or a single array/list of a type with two members" – MarkJ Jul 29 '13 at 13:31