Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.String(SByte*, Int32, Int32, Encoding) Constructor

Initializes a new instance of the String class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting character position within that array, a length, and an Encoding object.

This constructor is not CLS-compliant.  

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

public String (
	sbyte* value,
	int startIndex,
	int length,
	Encoding enc
Not applicable.



A pointer to an array of 8-bit signed integers.


The starting position within value.


The number of characters within value to use.


An Encoding object that specifies how the array referenced by value is encoded. If enc is a null reference (Nothing in Visual Basic), ANSI encoding is assumed.

Exception typeCondition


value is a null reference (Nothing in Visual Basic).


startIndex or length is less than zero.


The address specified by value + startIndex is too large for the current platform; that is, the address calculation overflowed.


The length of the new string to initialize is too large to allocate.


The address specified by value + startIndex is less than 64K.


A new instance of String could not be initialized using value, assuming value is encoded as specified by enc.


value, startIndex, and length collectively specify an invalid address.

The value parameter is assumed to point to a signed byte array representing a string encoded as specified by the enc parameter. The enc parameter is an System.Text.Encoding object that represents any valid encoding method. It must represent the same method of encoding used to create the byte array or the decoded string will not necessarily be identical to the original string.

If length is zero, the new instance is initialized to the empty string ("").

This constructor processes characters from value starting at startIndex and ending at (startIndex + length - 1).

If the specified range is outside of the memory allocated for the sequence of characters, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation.

In C#, this constructor is defined only in the context of unsafe code.

The following simple code example demonstrates how you can create an instance of a UTF-8 String with this constructor.

    String utfeightstring = null;
    sbyte [] asciiChars = new sbyte[] { 0x51,0x52,0x53,0x54,0x54,0x56 };
    UTF8Encoding encoding = new UTF8Encoding(true, true);

    // Instruct the Garbage Collector not to move the memory
    fixed(sbyte* pAsciiChars = asciiChars)
        utfeightstring = new String(pAsciiChars,0,asciiChars.Length,encoding);
    Console.WriteLine("The UTF8 String is " + utfeightstring ); // prints "QRSTTV"

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

© 2017 Microsoft