• 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++/CLI, you have other alternatives:

VB.NET C++/CLI (assuming an integer array)
ReDim Preserve YourArray(1, 2) array<int, 2> ^tempVar = gcnew array<int, 2>(2,3);
if (YourArray != nullptr)
{
    for (int Dim0 = 0; Dim0 < YourArray->GetLength(0); Dim0++)
    {
        int CopyLength = System::Math::Min(YourArray->GetLength(1), tempVar->GetLength(1));
        for (int Dim1 = 0; Dim1 < CopyLength; Dim1++)
        {
            tempVar[Dim0, Dim1] = YourArray[Dim0, Dim1];
        }
    }
}
YourArray = tempVar;


Use VB to C++ Converter to convert from VB to C++.     

Additional resource: VB.NET and C++ Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.