String 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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
为 null
。
如果 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
内的字符数。
- 属性
例外
startIndex
或 length
小于零,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
内的字符数。
例外
value
为 null
。
注解
注意
有关此构造函数重载和其他 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
参数
- startIndex
- Int32
value
内的起始位置。
- length
- Int32
要使用的 value
内的字符数。
- 属性
例外
value
为 null
。
startIndex
或 length
小于零。
或
由 value
+ startIndex
指定的地址对于当前平台而言太大;也就是说,此地址计算溢出。
或
要初始化的新字符串的长度太大,无法分配。
value
、startIndex
和 length
共同指定的地址无效。
注解
注意
有关此构造函数重载和其他 String
构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。
适用于
String(SByte*, Int32, Int32, Encoding)
- Source:
- String.cs
- Source:
- String.cs
- Source:
- String.cs
重要
此 API 不符合 CLS。
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
所引用的数组进行编码。 如果 enc
为 null
,则假定以 ANSI 编码。
- 属性
例外
value
为 null
。
startIndex
或 length
小于零。
或
由 value
+ startIndex
指定的地址对于当前平台而言太大;也就是说,此地址计算溢出。
或
要初始化的新字符串的长度太大,无法分配。
value
、startIndex
和 length
共同指定的地址无效。
注解
注意
有关此构造函数重载和其他 String
构造函数重载的示例和综合用法信息,请参阅 String 构造函数摘要。
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈