O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

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.

Tip

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required