System.Runtime.InteropServices.OutAttribute Class

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

See Also: OutAttribute Members

Syntax

[System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class OutAttribute : Attribute

Remarks

You can apply this attribute to parameters.

The System.Runtime.InteropServices.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 System.Text.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 System.Runtime.InteropServices.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 System.Runtime.InteropServices.InAttribute and System.Runtime.InteropServices.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 System.Runtime.InteropServices.InAttribute and System.Runtime.InteropServices.OutAttribute to reduce unnecessary copies.

For more information on the effect of System.Runtime.InteropServices.OutAttribute on marshaling behavior, see [<topic://cpcondirectionalattributes>].

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0