Reputation: 9847
In vb.net the methods have their parameters using ByVal by default, it's better practice / common practice to make it explicit?
For example:
With ByVal:
Private Sub MySub(ByVal Q As String)
{
' ...
}
End Sub
Without ByVal:
Private Sub MySub(Q As String)
{
' ...
}
End Sub
Upvotes: 5
Views: 1786
Reputation: 1576
Starting with VS 2010 SP1, ByVal
is no longer automatically inserted by the IDE.
I personally think it's better not to insert ByVal
manually, because:
ByVal
nor ByRef
are explicitly specified.ByVal
from method signature makes ByRef
stand out.ByVal
s.Upvotes: 3
Reputation: 94643
It is common practice that a method arguments can be specified at ByValue or ByReference. In VB.NET, the default argument type is ByVal
. In many programming language, method arguments are by-value
by default. If argument is not qualified with ByVal
or ByRef
then the argument type will be ByVal.
Upvotes: 0
Reputation: 239764
According to Microsoft:
It is good programming practice to include either the ByVal or ByRef keyword with every declared parameter.
And if you use Visual Studio, it defaults to inserting ByVal
if you don't explicitly specify it.
Upvotes: 5