Skip to content

VB -> C#: ReDim Preserve of array property  #1156

@gaschd

Description

@gaschd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    VB -> C#Specific to VB -> C# conversion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions