7.13. Passing Arguments: Pass-by-Value vs. Pass-by-Reference

Arguments are passed in one of two ways: pass-by-value and pass-by-reference. When an argument is passed by value, the program makes a copy of the argument’s value and passes the copy to the called method. With pass-by-value, changes to the called method’s copy do not affect the original variable’s value in the caller. In contrast, when an argument is passed by reference, the caller gives the called method the ability to access and modify the caller’s original data directly. Fig. 7.10 demonstrates passing value-type arguments by value and by reference.

Figure 7.10. ByVal and ByRef used to pass value-type arguments.
					1
					' Fig. 7.10: ByRefTest.vb
					2
					' Demonstrates passing by value and ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition 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.