ClassSystem.Runtime.InteropServices.OutAttribute Applies ToParameter ConstructorNew( ) PropertiesNone defined DescriptionThe <Out> attribute defines an outbound parameter, a variation of a ByRef parameter. Memory allocation for ByRef parameters is managed by the caller of the procedure; parameters with the <Out> attribute applied have their memory allocation managed by the procedure itself. No value comes in from the caller; a return value only goes out through the parameter. This makes <Out> parameters far more efficient in remoting (calls across machines) and in web method calls. Usage at a GlanceAlthough you can define an out parameter using the <Out> attribute, the Visual Basic compiler does not enforce it. 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. Care must be taken to ensure that all <Out> parameters are passed ByRef, and that they are explicitly assigned a value before the method exits. ExampleImports System Imports System.Runtime.InteropServices Public Class Person Public Name As String Private standardAge As Integer Dim standardHeight As Integer Dim standardWeight As Integer Public Sub New(fullName As String) ' ----- Perhaps the initial fields would come from a ' database, but here they are just hard-coded. Name = fullName standardAge = 26 standardHeight = 73 standardWeight = 185 End Sub Public Sub GetStats(<Out> ByRef currentAge As Integer, _ <Out> ByRef currentHeight As Integer, _ <Out> ByRef currentWeight As Integer) currentAge = standardAge currentHeight = standardHeight currentWeight = standardWeight End Sub End Class Module GeneralCode Public Sub Main( ) Dim mrTypical As New Person("John Doe") Dim hisAge As Integer Dim hisHeight As Integer Dim hisWeight As Integer mrTypical.GetStats(hisAge, hisHeight, hisWeight) MsgBox(mrTypical.Name & " is " & hisHeight & " inches tall.") End Sub End Module |