In
and Out
attributesThe In
and Out
attributes are used to provide custom marshalling information for parameters. All combinations of these marshalling attributes are permitted.
[AttributeUsage(AttributeTargets.Parameter)] public class InAttribute: System.Attribute { public InAttribute() {…} } [AttributeUsage(AttributeTargets.Parameter)] public class OutAttribute: System.Attribute { public OutAttribute() {…} }
If a parameter is not decorated with either marshalling attribute, then it is marshalled based on the its parameter-modifiers, as follows. If the parameter has no modifiers then the marshalling is [In]
. If the parameter has the ref
modifier then the marshalling is [In, Out]
. If the parameter has the out
modifier then the marshalling is [Out]
.
Note that out
is a keyword, and Out
is an attribute. The example
class Class1 { void M([Out] out int i) { … } }
shows that the use of out as a parameter-modifier and the use of Out
in an attribute.