CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: Passing variable with parenthesis to ByRef parameter should reclassify it to it's value

Open Yozer opened this issue 3 years ago • 0 comments

VB.Net input code

Public Sub Main()
    Dim v As Integer = 5
    Test((v))
    Console.WriteLine(v) 'prints 5
End Sub

Public Sub Test(ByRef x As Integer)
    x = -1
End Sub

Erroneous output

public void Main()
{
    int v = 5;
    Test(ref v);
    Console.WriteLine(v); // prints -1
}

public void Test(ref int x) => x = -1;

Expected output

public void Main()
{
    int v = 5;
    int argv = v;
    Test(ref argv);
    Console.WriteLine(v); // prints 5
}

Details

  • Product in use: e.g. codeconverter.icsharpcode.net / VS extension / both
  • Version in use: e.g. 5.6.3 or a commit hash (if it's a 3rd party tool using this library, try one of the above) ab3f09675061f0599c5b0fe8429ba64e7398b241
  • Did you see it working in a previous version, which?
  • Any other relevant information to the issue, or your interest in contributing a fix.

sharplab.io

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/how-to-force-an-argument-to-be-passed-by-value

trivia: http://www.panopticoncentral.net/2003/09/16/how-the-subroutine-got-its-parenthesis/

Yozer avatar Jul 15 '22 14:07 Yozer