Search code examples
c#marshalling

What does param means in c# (not params)


I found the following attribute declaration.

     [param: MarshalAs(UnmanagedType.LPTStr)]

what param keyword means in this context and why should we use it ?


Solution

  • param is the Attribute Target. Quote from MSDN:

    The list of possible target values is shown in the following table.

     C#            Visual Basic    Applies to
    
    assembly Assembly Entire assembly module Module Current assembly module (which is different from a Visual Basic Module) field Not supported Field in a class or a struct event Not supported Event method Not supported Method or get and set property accessors param Not supported Method parameters or set property accessor parameters property Not supported Property return Not supported Return value of a method, property indexer, or get property accessor type Not supported Struct, class, interface, enum, or delegate

    In your example, the attribute is probably used for a property setter and assigns the attribute to the (implicit) value parameter.