Out Attribute |
System.Runtime.InteropServices.OutAttribute
Parameter
Defines the parameter to which it applies as an out parameter. An out parameter is a variation on a parameter passed by reference using the ByRef keyword. In the case of a parameter passed by reference, the caller of the method is responsible for allocating memory and passing its address to the caller, which can then modify the parameter value. In the case of an out parameter, memory for the parameter is allocated by the called method and only its value is returned to the caller. This makes out parameters rather than reference parameters far more efficient in remoting (i.e., calls across machines) and in web method calls.
|
New( )
None
Imports System Imports System.Runtime.InteropServices Public Class CPerson Private iAge, iHeight, iWeight As Integer Private sName As String Public Sub New(strName As String) 'Here we'd ordinarily perform a database lookup ' and assign values to the instance fields sName = strName iAge = 26 iHeight = 73 iWeight = 185 End Sub Public Sub GetStats(<Out> ByRef intAge As Integer, _ <Out> ByRef intHt As Integer, _ <Out> ByRef intWt As Integer) intAge = iAge intHt = iHeight intWt = iWeight End Sub End Class Module modMain Public Sub Main( ) Dim oPerson As New CPerson("John Doe") Dim iAge As Integer, iHeight As Integer, iWeight As Integer oPerson.GetStats(iAge, iHeight, iWeight) Console.WriteLine("John Doe is " & iHeight & " inches tall.") End Sub End Module