Parameters Are Passed by Value


By default, in VBScript and earlier versions of Visual Basic, parameters passed to subroutines and functions are passed by reference. In Visual Basic .NET, however, parameters are passed by value.

When a parameter is passed to a function by value, changes to the parameter within the function are not reflected outside the function. When a parameter is passed by value, on the other hand, any changes made to the parameter are retained outside the function.

You can still use the ByVal and ByRef keywords to specify whether a parameter is passed by value or by reference. For example, the following page illustrates how to explicitly pass a parameter to a subroutine by value and by reference:

 
 <Script runat="Server"> Sub AddByVal( ByVal intParam )   intParam += 1 End Sub Sub AddByRef( ByRef intParam )   intParam +=1 End Sub </Script> <% Dim intNum As Integer = 3 ' intNum still equals 3 after AddByVal AddByVal( intNum ) ' intNum now equals 4 after AddByRef AddByRef( intNum ) %> 


ASP.NET Unleashed
ASP.NET 4 Unleashed
ISBN: 0672331128
EAN: 2147483647
Year: 2003
Pages: 263

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net