String 构造函数

定义

初始化 String 类的新实例。

重载

String(Char*)

String 类的新实例初始化为由指向 Unicode 字符数组的指定指针指示的值。

String(Char[])

String 类的新实例初始化为指定字符数组中指示的 Unicode 字符。

String(ReadOnlySpan<Char>)

String 类的新实例初始化为指定只读范围中指示的 Unicode 字符。

String(SByte*)

String 类的新实例初始化为由指向 8 位有符号整数数组的指针指示的值。

String(Char, Int32)

String 类的新实例初始化为由重复指定次数的指定 Unicode 字符指示的值。

String(Char*, Int32, Int32)

String 类的新实例初始化为由指向 Unicode 字符数组的指定指针指示的值、该数组内的起始字符位置和一个长度指示的值。

String(Char[], Int32, Int32)

String 类的新实例初始化为由 Unicode 字符数组、该数组内的起始字符位置和一个长度指示的值。

String(SByte*, Int32, Int32)

String 类的新实例初始化为由指向 8 位有符号整数数组的指定指针、该数组内的起始位置和一个长度指示的值。

String(SByte*, Int32, Int32, Encoding)

String 的新实例初始化为由指向 8 位有符号整数数组的指定指针、该数组内的起始位置、长度以及 Encoding 对象指示的值。

注解

有关此 API 的详细信息,请参阅 字符串构造函数的补充 API 备注

String(Char*)

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

重要

此 API 不符合 CLS。

String 类的新实例初始化为由指向 Unicode 字符数组的指定指针指示的值。

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

参数

value
Char*

指向以 null 终止的 Unicode 字符数组的指针。

属性

例外

当前进程不具有对所有通过地址访问的字符的读取访问权限。

value 指定的数组包含无效的 Unicode 字符,或 value 指定的地址小于 64000。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于

String(Char[])

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

String 类的新实例初始化为指定字符数组中指示的 Unicode 字符。

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

参数

value
Char[]

Unicode 字符的数组。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于

String(ReadOnlySpan<Char>)

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

String 类的新实例初始化为指定只读范围中指示的 Unicode 字符。

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

参数

value
ReadOnlySpan<Char>

Unicode 字符的只读范围。

适用于

String(SByte*)

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

重要

此 API 不符合 CLS。

String 类的新实例初始化为由指向 8 位有符号整数数组的指针指示的值。

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

参数

value
SByte*

一个指针,指向以 null 结尾的 8 位带符号整数数组。 使用当前系统代码页编码(即由 Default 指定的编码)来解释整数。

属性

例外

valuenull

如果 value 采用 ANSI 进行编码,那么无法使用 value 初始化 String 的新实例。

要初始化的新字符串的长度(该长度由 value 的 null 终止字符确定)太大,无法分配。

value 指定的地址无效。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于

String(Char, Int32)

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

String 类的新实例初始化为由重复指定次数的指定 Unicode 字符指示的值。

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)

参数

c
Char

一个 Unicode 字符。

count
Int32

c 出现的次数。

例外

count 小于零。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于

String(Char*, Int32, Int32)

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

重要

此 API 不符合 CLS。

String 类的新实例初始化为由指向 Unicode 字符数组的指定指针指示的值、该数组内的起始字符位置和一个长度指示的值。

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

参数

value
Char*

指向 Unicode 字符数组的指针。

startIndex
Int32

value 内的起始位置。

length
Int32

要使用的 value 内的字符数。

属性

例外

startIndexlength 小于零,value + startIndex 导致指针溢出,或者当前进程不具有对所有寻址字符的读取访问权限。

value 指定的数组包含无效的 Unicode 字符,或 value + startIndex 指定的地址小于 64000。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于

String(Char[], Int32, Int32)

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

String 类的新实例初始化为由 Unicode 字符数组、该数组内的起始字符位置和一个长度指示的值。

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)

参数

value
Char[]

Unicode 字符的数组。

startIndex
Int32

value 内的起始位置。

length
Int32

要使用的 value 内的字符数。

例外

valuenull

startIndexlength 小于零。

startIndexlength 的和大于 value 中的元素数。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于

String(SByte*, Int32, Int32)

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

重要

此 API 不符合 CLS。

String 类的新实例初始化为由指向 8 位有符号整数数组的指定指针、该数组内的起始位置和一个长度指示的值。

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

参数

value
SByte*

指向 8 位带符号整数数组的指针。 使用当前系统代码页编码(即由 Default 指定的编码)来解释整数。

startIndex
Int32

value 内的起始位置。

length
Int32

要使用的 value 内的字符数。

属性

例外

valuenull

startIndexlength 小于零。

value + startIndex 指定的地址对于当前平台而言太大;也就是说,此地址计算溢出。

要初始化的新字符串的长度太大,无法分配。

value + startIndex 指定的地址小于 64K。

如果 value 采用 ANSI 进行编码,那么无法使用 value 初始化 String 的新实例。

valuestartIndexlength 共同指定的地址无效。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于

String(SByte*, Int32, Int32, Encoding)

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

重要

此 API 不符合 CLS。

String 的新实例初始化为由指向 8 位有符号整数数组的指定指针、该数组内的起始位置、长度以及 Encoding 对象指示的值。

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

参数

value
SByte*

指向 8 位带符号整数数组的指针。

startIndex
Int32

value 内的起始位置。

length
Int32

要使用的 value 内的字符数。

enc
Encoding

一个对象,用于指定如何对 value 所引用的数组进行编码。 如果 encnull,则假定以 ANSI 编码。

属性

例外

valuenull

startIndexlength 小于零。

value + startIndex 指定的地址对于当前平台而言太大;也就是说,此地址计算溢出。

要初始化的新字符串的长度太大,无法分配。

value + startIndex 指定的地址小于 64K。

如果 value 按照指定的 enc 进行编码,那么无法使用 value 初始化 String 的新实例。

valuestartIndexlength 共同指定的地址无效。

注解

注意

有关此构造函数重载和其他 String 构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。

适用于