Name

MarshalAsAttribute

Synopsis

This optional attribute is used to explicitly specify the unmanaged type a parameter, field, or return value should be marshaled to. If you do not specify this attribute, .NET uses the type’s default marshaler. The UnmanagedType enumeration contains the unmanaged types you can marshal to with this attribute.

public sealed class MarshalAsAttribute : Attribute {
// Public Constructors
   public method MarshalAsAttribute(short unmanagedType);  
   public method MarshalAsAttribute(
        UnmanagedType unmanagedType);  
// Public Instance Fields
   public field UnmanagedType ArraySubType;  
   public field string MarshalCookie;  
   public field string MarshalType;  
   public field Type MarshalTypeRef;  
   public field VarEnum SafeArraySubType;  
   public field Type SafeArrayUserDefinedSubType;  
   public field int SizeConst;  
   public field short SizeParamIndex;  
// Public Instance Properties
   public field UnmanagedType Value{get; } 
}

Hierarchy

System.ObjectSystem.AttributeMarshalAsAttribute

Valid On

Field, Parameter, ReturnValue

Get C# in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.