System.Runtime.InteropServices.MarshalAsAttribute.SizeParamIndex Field

Indicates the zero-based parameter that contains the count of array elements, similar to size_is in COM.

Syntax

public short SizeParamIndex

Remarks

The MarshalAsAttribute.SizeParamIndex field supports managed-to-unmanaged and unmanaged-to-managed calls. It does not have any effect on managed code that calls COM objects.

Depending on the managed type and the attributes applied to it, the array can be passed as a safe array or C-style array.

When arrays are passed as C-style arrays, the marshaler cannot determine the size of the array. Therefore, to pass an managed array to an unmanaged function or method, you must provide two arguments:

  • The array, defined by reference or value.

  • The array size, defined by reference or value.

The zero-based index of the array size parameter is defined by using the MarshalAsAttribute.SizeParamIndex field.

If you specify both MarshalAsAttribute.SizeParamIndex and MarshalAsAttribute.SizeConst with a UnmanagedType.LPArray field, the sum of the fields' values produces a size total.

For more information, see [<topic://cpcondefaultmarshalingforarrays>].

Requirements

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