.NET Framework Class Library
OutAttribute Class

Indicates that data should be marshaled from callee back to caller.

Inheritance Hierarchy
SystemObject
   SystemAttribute
    System.Runtime.InteropServicesOutAttribute

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)
Syntax
<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_0_0_0%](True)> _
<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_0_0_1%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_0_0_2%].Parameter, Inherited := False)> _
Public NotInheritable Class OutAttribute _
	Inherits [%$TOPIC/k8189tfc_en-us_VS_110_2_0_0_0_3%]
[[%$TOPIC/k8189tfc_en-us_VS_110_2_0_1_0_0%](true)]
[[%$TOPIC/k8189tfc_en-us_VS_110_2_0_1_0_1%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_1_0_2%].Parameter, Inherited = false)]
public sealed class OutAttribute : [%$TOPIC/k8189tfc_en-us_VS_110_2_0_1_0_3%]
[[%$TOPIC/k8189tfc_en-us_VS_110_2_0_2_0_0%](true)]
[[%$TOPIC/k8189tfc_en-us_VS_110_2_0_2_0_1%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_2_0_2%]::Parameter, Inherited = false)]
public ref class OutAttribute sealed : public [%$TOPIC/k8189tfc_en-us_VS_110_2_0_2_0_3%]
[<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_0%]>]
[<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_1%](true)>]
[<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_2%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_3%].Parameter, Inherited = false)>]
type OutAttribute =  
    class 
        inherit [%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_4%] 
    end

The OutAttribute type exposes the following members.

Constructors
  NameDescription
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps OutAttributeInitializes a new instance of the OutAttribute class.
Top
Properties
  NameDescription
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top
Methods
  NameDescription
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method Supported by the XNA Framework MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top
Remarks

You can apply this attribute to parameters.

The OutAttribute is optional. The attribute is supported for COM interop and platform invoke only. In the absence of explicit settings, the interop marshaler assumes rules based on the parameter type, whether the parameter is passed by reference or by value, and whether the type is blittable or non-blittable. For example, the StringBuilder class is always assumed to be In/Out and an array of strings passed by value is assumed to be In.

Out-only behavior is never a default marshaling behavior for parameters. You can apply the OutAttribute to value and reference types passed by reference to change In/Out behavior to Out-only behavior, which is equivalent to using the out keyword in C#. For example, arrays passed by value, marshaled as In-only parameters by default, can be changed to Out-only. However, the behavior does not always provide expected semantics when the types include all-blittable elements or fields because the interop marshaler uses pinning. If you do not care about passing data into the callee, Out-only marshaling can provide better performance for non-blittable types.

Combining the InAttribute and OutAttribute is particularly useful when applied to arrays and formatted, non-blittable types. Callers see the changes a callee makes to these types only when you apply both attributes. Since these types require copying during marshaling, you can use InAttribute and OutAttribute to reduce unnecessary copies.

For more information on the effect of OutAttribute on marshaling behavior, see Directional Attributes.

Examples

The following example shows how to apply the InAttribute and OutAttribute to a platform invoke prototype that passes an array as a parameter. The combination of directional attributes allows the caller to see the changes made by the callee.

Imports System.Runtime.InteropServices


' Declare a class member for each structure element.
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Class OpenFileName

   Public structSize As Integer = 0
   Public filter As String = Nothing 
   Public file As String = Nothing 
   ' ... 

End Class 'OpenFileName

Public Class LibWrap
   ' Declare managed prototype for the unmanaged function. 
   Declare Unicode Function GetOpenFileName Lib "Comdlg32.dll" ( _
      <[In](), Out()> ByVal ofn As OpenFileName) As Boolean 
End Class 'LibWrap

Public Class App
    Public Shared Sub Main()

    End Sub 'Main
End Class 'App
using System.Runtime.InteropServices;
using System;


// Declare a class member for each structure element.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class OpenFileName
{
    public int structSize = 0;
    public string filter = null;
    public string file = null;
    // ...
}

public class LibWrap
{
    // Declare a managed prototype for the unmanaged function.
    [DllImport("Comdlg32.dll", CharSet = CharSet.Unicode)]
    public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
}

public class MainMethod
{
    static void Main()
    { }

}
using namespace System;
using namespace System::Runtime::InteropServices;


// Declare a class member for each structure element.

[StructLayout(LayoutKind::Sequential,CharSet=CharSet::Unicode)]
public ref class OpenFileName
{
public:
   int structSize;
   String^ filter;
   String^ file;
   // ...
};

public ref class LibWrap
{
public:

   // Declare a managed prototype for the unmanaged function.

   [DllImport("Comdlg32.dll",CharSet=CharSet::Unicode)]
   static bool GetOpenFileName( [In,Out]OpenFileName^ ofn );
};

void main() {}
Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Platforms

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.