Skip to content

VB -> C#: out param is set after return #896

Description

@KunzeAndreas

VB.Net input code

Private Shared Sub ReturnWithOutParam()
    Dim testclass = New OutParamTestClass
    Assert.That(testclass.Number = 2)

    Dim dummy = CallSubWithOutParam(testclass)
    Assert.That(testclass.Number = 1)
End Sub
Private Shared Function CallSubWithOutParam(testClass As OutParamTestClass) As Boolean
    Return SubWithOutParam(testClass.Number)
End Function
Private Shared Function SubWithOutParam(<Out> ByRef out_a As Integer) As Boolean
    out_a = 1
    Return True
End Function
Private Class OutParamTestClass
    Friend Property Number As Integer = 2
End Class

Erroneous output

private static void ReturnWithOutParam()
{
    var testclass = new OutParamTestClass();
    Assert.That(testclass.Number == 2);

    bool dummy = CallSubWithOutParam(testclass);
    Assert.That(testclass.Number == 1);
}
private static bool CallSubWithOutParam(OutParamTestClass testClass)
{
    int argout_a = testClass.Number;
    return SubWithOutParam(out argout_a);
    testClass.Number = argout_a;
}
private static bool SubWithOutParam(out int out_a)
{
    out_a = 1;
    return true;
}
private class OutParamTestClass
{
    internal int Number { get; set; } = 2;
}

Expected output

private static bool CallSubWithOutParam(OutParamTestClass testClass)
{        
    int argout_a = testClass.Number;
    var result= SubWithOutParam(out argout_a);
    testClass.Number = argout_a;
    return result;
}

Details

  • Product in use: VS extension
  • Version in use: 9.0.0.0
  • Did you see it working in a previous version, which? no

Activity

  1. added
    VB -> C#
    on May 16, 2022
  2. added
    output logic error
    on May 16, 2022
  3. added
    Good for coding agent
    on Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good for coding agentVB -> C#output logic error

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions