Out Attribute

   
Out Attribute

Class

System.Runtime.InteropServices.OutAttribute

Applies to

Parameter

Description

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.

Although you can define an out parameter using the <Out> attribute, the VB.NET compiler does not enforce it. That is, if you fail to assign a value to the out parameter, or if you indicate that the parameter is to be passed by value rather than by reference, the compiler does not generate an error. Because of this, be especially careful to make sure that all parameters marked with the <Out> attribute are passed using the ByRef keyword, and that you've explicitly assigned a value to the out parameter in the method.

Constructor

 New(  ) 

Properties

None

Example

 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 
   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

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