Parameters

I l @ ve RuBoard

Another way to define variables is through the use of formal method parameters. Table C.1 outlines the four types of method parameters.

Table C.1. Parameter Types in VB.NET
Parameter Type Modifier Description
value ByVal Modifications do not impact original argument passed into the method
reference ByRef Modifications directly impact original argument passed into the method
optional Optional Does not require the argument to be supplied; however, a default value must be supplied in the argument declaration
parameter array ParamArray Enables variable length parameter lists

Consider the following class that employs each of the parameter types:

  Imports System Class Test     Sub ValueParamMethod(a As Integer)         a =  a + 2 ' the orginal parameter is not modified     End Sub     Sub RefParamMethod(ByRef a As Integer)         a =  a + 2 ' the orginal parameter is not modified     End Sub     Sub OptionalParamMethod(Optional a As Integer = 3)         a =  a + 2 ' if a is not supplied, defaults to 3     End Sub     Sub ParamArrayMethod(ParamArray args As Integer)         ' provides flexibility through indefinite number of arguments     End Sub End Class 
I l @ ve RuBoard


Asp. Net. By Example
ASP.NET by Example
ISBN: 0789725622
EAN: 2147483647
Year: 2001
Pages: 154

Similar book on Amazon

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