param在c#中意味着什么(不是params)
What does param means in c# (not params)
我找到了以下属性声明。
[param: MarshalAs(UnmanagedType.LPTStr)]
param 关键字在此上下文中意味着什么,我们为什么要使用它?
param
是 属性目标 。引自 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
在您的示例中,属性可能用于 属性 setter 并将属性分配给(隐式)value
参数。
这与使用 MarshalAs 属性的编组处理有关,其中 UnmanagedType.LPTStr 表示它正在编组为 unicode 字符。 ' 'param' 用作属性标记。正如 Heinzi 提到的,在 C# 中允许使用上述目标值,这里它用于 属性 值参数。
我找到了以下属性声明。
[param: MarshalAs(UnmanagedType.LPTStr)]
param 关键字在此上下文中意味着什么,我们为什么要使用它?
param
是 属性目标 。引自 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
在您的示例中,属性可能用于 属性 setter 并将属性分配给(隐式)value
参数。
这与使用 MarshalAs 属性的编组处理有关,其中 UnmanagedType.LPTStr 表示它正在编组为 unicode 字符。 ' 'param' 用作属性标记。正如 Heinzi 提到的,在 C# 中允许使用上述目标值,这里它用于 属性 值参数。