Indicates that data should be marshaled from callee back to caller.
Assembly: mscorlib (in mscorlib.dll)
<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_0_0_0%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_0_0_1%].Parameter, Inherited := False)> _
<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_0_0_2%](True)> _
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%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_1_0_1%].Parameter, Inherited = false)]
[[%$TOPIC/k8189tfc_en-us_VS_110_2_0_1_0_2%](true)]
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%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_2_0_1%]::Parameter, Inherited = false)]
[[%$TOPIC/k8189tfc_en-us_VS_110_2_0_2_0_2%](true)]
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%]([%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_2%].Parameter, Inherited = false)>]
[<[%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_3%](true)>]
type OutAttribute =
class
inherit [%$TOPIC/k8189tfc_en-us_VS_110_2_0_3_0_4%]
end
The OutAttribute type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | OutAttribute | Initializes a new instance of the OutAttribute class. |
| Name | Description | |
|---|---|---|
![]() | Equals | Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.) |
![]() | GetHashCode | Returns the hash code for this instance. (Inherited from Attribute.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | IsDefaultAttribute | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.) |
![]() | Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | _AttributeGetIDsOfNames | Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.) |
![]() | _AttributeGetTypeInfo | Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.) |
![]() | _AttributeGetTypeInfoCount | Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.) |
![]() | _AttributeInvoke | Provides access to properties and methods exposed by an object. (Inherited from Attribute.) |
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.
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() {}
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.
.png)
.gif)
.gif)