Mono Class Library: Mono.Unix.UnixMarshal Overview | Members

Mono.Unix.UnixMarshal.PtrToStringArray Method

Allocates a string array and unmarshals the unmanaged string array into a managed string array using the specified encoding.

public static string[] PtrToStringArray (IntPtr stringArray, System.Text.Encoding encoding)

Parameters

stringArray
A IntPtr containing a byte** array which follows the ANSI C rules for the argv argument passed to main.
encoding
A stem.Text.Encoding specifying the encoding of the unmanaged strings within stringArray.

Returns

A string array containing all the strings in the unmanaged string array. If stringArray is IntPtr.Zero, a string array containing zero elements is returned.

Exceptions

TypeReason
ArgumentNullExceptionencoding is null.

Remarks

stringArray is assumed to be a Cchar** pointer containing a terminating IntPtr.Zero pointer to designate the end of the array. This follows the requirements for argv in the ANSI C main function declaration.

C Example

static const char* 
stringArray[] = {
    "string 1",
    "string 2",
    NULL
};
          

The final null string will not be returned from this method; the above stringArray declaration would create an array containing two elements if passed through this method.

Requirements

Namespace: Mono.Unix
Assembly: Mono.Posix (in Mono.Posix.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0