VB to .NET

Using ByRef arguments in Interfaces Methods

The VBUC provides a feature that removes ByRef arguments when the argument is not being changed inside the method. As we don’t know all the implementing classes for an interface and the use of the argument inside all the implementing methods, we are avoiding this feature for the methods interfaces. This means that if there is a ByRef argument in an exposed method inside an interface, this argument won’t be changed to ByVal. In addition, this argument in all implementing methods will be ByRef too.

The feature that changes ByRef arguments to ByVal is only applied for C# upgrading, so this interface feature applies just for C# too.

Original VB6 code

AnInterface.cls

Sub goo(arg1 As Integer)
End Sub
Function foo(ByRef arg1 As Integer) As String
End Function

AClass.cls

Implements AnInterface
Sub AnInterface_goo(arg1 As Integer)
End Sub
Function AnInterface_foo(ByRef arg1 As Integer) As String
End Function

VBUC resulting C#.NET code

AnInterface.cls

    public void  goo(ref  int arg1)
    {
    }
    public string foo(ref  int arg1)
    {
        return String.Empty;
    }

AClass.cls

    internal class AClass
    : AnInterface
    {
    
        public void  goo(ref  int arg1)
        {
        }
        
        public string foo(ref  int arg1)
        {
            return String.Empty;
        }
    }
Talk To An Engineer