This documentation is archived and is not being maintained.

MarshalAsAttribute.SizeParamIndex Field

Indicates which parameter contains the count of array elements, much like size_is in COM, and is zero-based.

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

public short SizeParamIndex

This field is used when building managed objects that work with COM. SizeParamIndex is valid only on managed methods that are called from COM clients, where one of the parameters is an array. Because the marshaler cannot determine the size of an unmanaged array, this information is passed in a separate parameter.

The parameter containing the size must be an integer that is passed by value. If you specify both the SizeParamIndex and MarshalAsAttribute.SizeConst with a UnmanagedType.LPArray, the sum of their values produces a size total. For additional information, see Default Marshaling for Arrays.

using System.Runtime.InteropServices;
using SomeNamespace;

namespace SomeNamespace
    // Force the layout of your fields to the C style struct layout. 
    // Without this, the .NET Framework will reorder your fields.
    public struct Vertex
    	float	x;
	float	y;
    	float	z;

    class SomeClass
        // Add [In] or [In, Out] attributes as approppriate. 
        // Marshal as a C style array of Vertex, where the second (SizeParamIndex is zero-based) 
        //  parameter (size) contains the count of array elements.
        [DllImport ("SomeDll.dll")]
        public static extern void SomeUnsafeMethod(
                                      [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] Vertex[] data,
                                      long size );

        public void SomeMethod()
            Vertex[] verts = new Vertex[3];
            SomeUnsafeMethod( verts, verts.Length );


class Test
	public static void Main()
        SomeClass AClass = new SomeClass();


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0