Marshaling Arrays of Types

An array is a reference type in managed code that contains one or more elements of the same type. Although arrays are reference types, they are passed as In parameters to unmanaged functions. This behavior is inconsistent with way managed arrays are passed to managed objects, which is as In/Out parameters. For additional details, see Copying and Pinning.

The following table lists marshaling options for arrays and describes their usage. For the corresponding platform invoke sample, see Arrays.

Array

Description

Of integers by value.

Passes an array of integers as an In parameter.

Of integers by reference.

Passes an array of integers as an In/Out parameter.

Of integers by value (two-dimensional).

Passes a matrix of integers as an In parameter.

Of strings by value.

Passes an array of strings as an In parameter.

Of structures with integers.

Passes an array of structures that contain integers as an In parameter.

Of structures with strings.

Passes an array of structures that contain only integers as an In/Out parameter. Members of the array can be changed.

See Also

Concepts

Platform Invoke Data Types

Marshaling Strings

Marshaling Classes, Structures, and Unions

Miscellaneous Marshaling Samples

Copying and Pinning

Other Resources

Marshaling Data with Platform Invoke