• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

C# Equivalent to VB ReDim Preserve

Resizing arrays while preserving the existing contents is easily done in VB using ReDim Preserve.  In C#, you have other alternatives:

VB C#
Dim YourArray() As Integer
...
ReDim Preserve YourArray(i)
int[] YourArray;
...
//C# 2005 and beyond:
Array.Resize(ref YourArray, i + 1);

//C# prior to 2005:
int[] temp = new int[i + 1];
if (YourArray != null)
    Array.Copy(YourArray, temp, Math.Min(YourArray.Length, temp.Length));
YourArray = temp;


Use Instant C# and Instant VB to convert between VB.NET and C#.     

Additional resource: VB.NET and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.