CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: ReDim Preserve of array property

Open gaschd opened this issue 1 year ago • 0 comments

Converting ReDim Preserve on an array property throws CS0206: A property or indexer may not be passed as an out or ref parameter while Array.Resize is converted correctly by utilizing a local variable for this case.

VB.Net input code

Public Class TestClass
    Public Property NumArray1 As Integer()

    Public Sub New()
        Array.Resize(NumArray1, 3)

        ReDim Preserve NumArray1(4)
    End Sub
End Class

Erroneous output

using System;
              
public partial class TestClass
{
public int[] NumArray1 { get; set; }

public TestClass()
{
    var argarray = NumArray1;
    Array.Resize(ref argarray, 3);
    NumArray1 = argarray;

    Array.Resize(ref this.NumArray1, 5);
}

Expected output

using System;

public partial class TestClass
{
    public int[] NumArray1 { get; set; }    

    public TestClass()
    {
        var argarr = NumArray1;
        Array.Resize(ref argarr, 3);
        NumArray1 = argarr;

        var argarr1 = NumArray1;
        Array.Resize(ref argarr1, 5);
        NumArray1 = argarr1;
    }
}

Details

  • Product in use: VS extension
  • Version in use: master abea701

gaschd avatar Nov 10 '24 10:11 gaschd