Passing Arguments by Value

By default, arguments in Visual Basic .NET receive a copy of any argument values the calling statement specifies. The term for this is receiving an argument by value. Suppose, for example, you wrote a subroutine named ZeroOut that contained this code:

Sub ZeroOut(intArg As Integer)
    intArg = 0  ' Zero out first argument
End Sub

So far, so good. Now suppose that you called the subroutine with this code:

Dim intCount As Integer = 5
ZeroOut(intCount)
MsgBox("The count is " & intCount)

If you ran this code, you’d find that the value of intCount remains 5 even though you passed it as the first argument to the ZeroOut subroutine, and even though the ZeroOut subroutine zeroes out the first argument! This is because the ZeroOut subroutine ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.