Επεξεργασία

Κοινή χρήση μέσω


String Constructors

Definition

Initializes a new instance of the String class.

Overloads

String(Char*)

Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters.

String(Char[])

Initializes a new instance of the String class to the Unicode characters indicated in the specified character array.

String(ReadOnlySpan<Char>)

Initializes a new instance of the String class to the Unicode characters indicated in the specified read-only span.

String(SByte*)

Initializes a new instance of the String class to the value indicated by a pointer to an array of 8-bit signed integers.

String(Char, Int32)

Initializes a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times.

String(Char*, Int32, Int32)

Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters, a starting character position within that array, and a length.

String(Char[], Int32, Int32)

Initializes a new instance of the String class to the value indicated by an array of Unicode characters, a starting character position within that array, and a length.

String(SByte*, Int32, Int32)

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 position within that array, and a length.

String(SByte*, Int32, Int32, Encoding)

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 position within that array, a length, and an Encoding object.

Remarks

For more information about this API, see Supplemental API remarks for String constructor.

String(Char*)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Important

This API is not CLS-compliant.

Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters.

public:
 String(char* value);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public String (char* value);
[System.CLSCompliant(false)]
public String (char* value);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
new string : nativeptr<char> -> string
[<System.CLSCompliant(false)>]
new string : nativeptr<char> -> string

Parameters

value
Char*

A pointer to a null-terminated array of Unicode characters.

Attributes

Exceptions

The current process does not have read access to all the addressed characters.

value specifies an array that contains an invalid Unicode character, or value specifies an address less than 64000.

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to

String(Char[])

Source:
String.cs
Source:
String.cs
Source:
String.cs

Initializes a new instance of the String class to the Unicode characters indicated in the specified character array.

public:
 String(cli::array <char> ^ value);
public String (char[] value);
public String (char[]? value);
new string : char[] -> string
Public Sub New (value As Char())

Parameters

value
Char[]

An array of Unicode characters.

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to

String(ReadOnlySpan<Char>)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Initializes a new instance of the String class to the Unicode characters indicated in the specified read-only span.

public:
 String(ReadOnlySpan<char> value);
public String (ReadOnlySpan<char> value);
new string : ReadOnlySpan<char> -> string
Public Sub New (value As ReadOnlySpan(Of Char))

Parameters

value
ReadOnlySpan<Char>

A read-only span of Unicode characters.

Applies to

String(SByte*)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Important

This API is not CLS-compliant.

Initializes a new instance of the String class to the value indicated by a pointer to an array of 8-bit signed integers.

public:
 String(System::SByte* value);
[System.CLSCompliant(false)]
public String (sbyte* value);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public String (sbyte* value);
[<System.CLSCompliant(false)>]
new string : nativeptr<sbyte> -> string
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
new string : nativeptr<sbyte> -> string

Parameters

value
SByte*

A pointer to a null-terminated array of 8-bit signed integers. The integers are interpreted using the current system code page encoding on Windows (referred to as CP_ACP) and as UTF-8 encoding on non-Windows.

Attributes

Exceptions

value is null.

A new instance of String could not be initialized using value, assuming value is encoded in ANSI.

The length of the new string to initialize, which is determined by the null termination character of value, is too large to allocate.

value specifies an invalid address.

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to

String(Char, Int32)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Initializes a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times.

public:
 String(char c, int count);
public String (char c, int count);
new string : char * int -> string
Public Sub New (c As Char, count As Integer)

Parameters

c
Char

A Unicode character.

count
Int32

The number of times c occurs.

Exceptions

count is less than zero.

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to

String(Char*, Int32, Int32)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Important

This API is not CLS-compliant.

Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters, a starting character position within that array, and a length.

public:
 String(char* value, int startIndex, int length);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public String (char* value, int startIndex, int length);
[System.CLSCompliant(false)]
public String (char* value, int startIndex, int length);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
new string : nativeptr<char> * int * int -> string
[<System.CLSCompliant(false)>]
new string : nativeptr<char> * int * int -> string

Parameters

value
Char*

A pointer to an array of Unicode characters.

startIndex
Int32

The starting position within value.

length
Int32

The number of characters within value to use.

Attributes

Exceptions

startIndex or length is less than zero, value + startIndex cause a pointer overflow, or the current process does not have read access to all the addressed characters.

value specifies an array that contains an invalid Unicode character, or value + startIndex specifies an address less than 64000.

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to

String(Char[], Int32, Int32)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Initializes a new instance of the String class to the value indicated by an array of Unicode characters, a starting character position within that array, and a length.

public:
 String(cli::array <char> ^ value, int startIndex, int length);
public String (char[] value, int startIndex, int length);
new string : char[] * int * int -> string
Public Sub New (value As Char(), startIndex As Integer, length As Integer)

Parameters

value
Char[]

An array of Unicode characters.

startIndex
Int32

The starting position within value.

length
Int32

The number of characters within value to use.

Exceptions

value is null.

startIndex or length is less than zero.

-or-

The sum of startIndex and length is greater than the number of elements in value.

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to

String(SByte*, Int32, Int32)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Important

This API is not CLS-compliant.

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 position within that array, and a length.

public:
 String(System::SByte* value, int startIndex, int length);
[System.CLSCompliant(false)]
public String (sbyte* value, int startIndex, int length);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public String (sbyte* value, int startIndex, int length);
[<System.CLSCompliant(false)>]
new string : nativeptr<sbyte> * int * int -> string
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
new string : nativeptr<sbyte> * int * int -> string

Parameters

value
SByte*

A pointer to an array of 8-bit signed integers. The integers are interpreted using the current system code page encoding on Windows (referred to as CP_ACP) and as UTF-8 encoding on non-Windows.

startIndex
Int32

The starting position within value.

length
Int32

The number of characters within value to use.

Attributes

Exceptions

value is null.

startIndex or length is less than zero.

-or-

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

-or-

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

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

-or-

A new instance of String could not be initialized using value, assuming value is encoded in ANSI.

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

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to

String(SByte*, Int32, Int32, Encoding)

Source:
String.cs
Source:
String.cs
Source:
String.cs

Important

This API is not CLS-compliant.

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 position within that array, a length, and an Encoding object.

public:
 String(System::SByte* value, int startIndex, int length, System::Text::Encoding ^ enc);
[System.CLSCompliant(false)]
public String (sbyte* value, int startIndex, int length, System.Text.Encoding enc);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public String (sbyte* value, int startIndex, int length, System.Text.Encoding enc);
[<System.CLSCompliant(false)>]
new string : nativeptr<sbyte> * int * int * System.Text.Encoding -> string
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
new string : nativeptr<sbyte> * int * int * System.Text.Encoding -> string

Parameters

value
SByte*

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

startIndex
Int32

The starting position within value.

length
Int32

The number of characters within value to use.

enc
Encoding

An object that specifies how the array referenced by value is encoded. If enc is null, ANSI encoding is assumed.

Attributes

Exceptions

value is null.

startIndex or length is less than zero.

-or-

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

-or-

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

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

-or-

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.

Remarks

Note

For examples and comprehensive usage information about this and other String constructor overloads, see the String constructor summary.

Applies to