VB to .NET

WARNING #1003

ParamArray 1% was changed from ByRef to ByVal.

Description

In Visual Basic, the Param Array keyword could be used to specify an arbitrary number of parameters for a declaration, sub, or function. ParamArrays were always passed by reference (ByRef).

In Visual Basic .NET, ParamArrays are always passed by value; the Param Array keyword must be preceded by the ByVal keyword.

When a parameter is passed by value, a copy of the variable is passed; when passed by reference, a pointer to the variable is passed. When passing by value, it is possible that the value of the variable may have changed and that the copy is out of date.

Recommendations

Review the code to make sure that the variables being passed as parameters are not being changed between the time that they are set and the time that they are used in a procedure. If necessary, modify your code so that the procedure executes before the variables are modified.

Sample VB6

Private Sub Form_Load()
    Dim myArray(0 To 2) As String
    myArray(0) = "First"
    myArray(1) = "Second"
    myArray(2) = "Third"
    
    Example myArray(0), myArray(1), myArray(2)
    MsgBox myArray(1)
End Sub

Public Sub Example(ParamArray params() As Variant)
    MsgBox "Second Parameter: " + params(1)
    params(1) = params(1) + "_modified"
End Sub


Target VB.NET

Private Sub Form_Load()
	Dim myArray(2) As String
	myArray(0) = "First"
	myArray(1) = "Second"
	myArray(2) = "Third"

	Example(myArray(0), myArray(1), myArray(2))
	MessageBox.Show(myArray(1), My.Application.Info.Title)
End Sub

'UPGRADE_WARNING: (1003) ParamArray params was changed from ByRef to ByVal.
Public Sub Example(ParamArray ByVal params() As Object)
	MessageBox.Show("Second Parameter: " & ReflectionHelper.GetPrimitiveValue(Of String)(params(1)), My.Application.Info.Title)
	params(1) = ReflectionHelper.GetPrimitiveValue(Of String)(params(1)) & "_modified"
End Sub


Target C# 

private void Form_Load()
{
	string[] myArray = new string[]{"", "", ""};
	myArray[0] = "First";
	myArray[1] = "Second";
	myArray[2] = "Third";

	Example(myArray[0], myArray[1], myArray[2]);
	MessageBox.Show(myArray[1], AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));
}

//UPGRADE_WARNING: (1003) ParamArray params was changed from ByRef to ByVal.
public void Example(params object[] params_Renamed)
{
	MessageBox.Show("Second Parameter: " + ReflectionHelper.GetPrimitiveValue<string>(params_Renamed[1]), AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));
	params_Renamed[1] = ReflectionHelper.GetPrimitiveValue<string>(params_Renamed[1]) + "_modified";
}
 
 
 
Talk To An Engineer