array redim and redim preserve

Greetings All,

The following is the vb.net code i need equilant C# code. can anybody pls help me to complete the following

Dim vaResultSet

If Not IsArray(vaResultSet) Then

ReDim vaResultSet(0)

Else

ReDim Preserve vaResultSet(UBound(vaResultSet) + 1)

End If


Thanks in advance
sai



Answer this question

array redim and redim preserve

  • jiangsheng

    Thanks for your information
  • Paul S

    Sadly, Microsoft were forced to preserve a lot of VB6 *** in VB.NET. Read this link:

    http://www.aspheute.com/english/20001025.asp

    and then consider throwing this rubbish away in favour of a proper dynamic array.



  • JUNKMAN

    As Christian said, you should use a proper dynamic array such as ArrayList, but here is a translation:

    object[] vaResultSet = null;

    if (vaResultSet == null)
    vaResultSet = new object[1];
    else
    {
    //INSTANT C# NOTE: The following 4 lines reproduce what 'ReDim Preserve' does behind the scenes in VB.NET:
    //ORIGINAL LINE: ReDim Preserve vaResultSet(UBound(vaResultSet) + 1)
    object[] tempReDim1 = new object[vaResultSet.GetUpperBound(0) + 2];
    if (vaResultSet != null)
    System.Array.Copy(vaResultSet, tempReDim1, System.Math.Min(vaResultSet.Length, tempReDim1.Length));
    vaResultSet = tempReDim1;
    }

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# converter
    Instant VB: C# to VB.NET converter
    Instant C++: C# to C++ converter and VB to C++ converter
    Instant J#: VB.NET to J# converter
    Clear VB: Cleans up VB.NET code



  • array redim and redim preserve