Using ByVal in vb.net methods, what is the common practice?

In vb.net, methods have their own parameters, using ByVal by default, is it better to practice / spread the practice to make this explicit?

For instance:

With ByVal:

Private Sub MySub(ByVal Q As String) { ' ... } End Sub 

Without ByVal:

 Private Sub MySub(Q As String) { ' ... } End Sub 
+4
source share
3 answers

According to Microsoft :

Good programming practice includes either the ByVal keyword or ByRef with each parameter declared.

And if you use Visual Studio, by default it inserts ByVal , unless you explicitly specify it.

+5
source

Starting with VS 2010 SP1, ByVal will no longer be automatically inserted into the IDE.

I personally think that it’s better not to insert ByVal manually, because:

  • this is the default transfer mechanism anyway unless ByVal and ByRef are explicitly ByVal .
  • ByVal exception to the method signature makes ByRef outstanding.
  • it adds β€œnoise” to the code. VB.Net is already very verbose, no need to clutter up the code with unnecessary ByVal s.
+2
source

It is generally believed that method arguments can be specified in ByValue or ByReference. In VB.NET, the default argument type is ByVal . In many programming languages, by-value method arguments are the default. If the argument does not meet the ByVal or ByRef criteria, then the type of the argument will be ByVal.

0
source

All Articles