String 建構函式

定義

初始化 String 類別的新執行個體。

多載

名稱 Description
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*)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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 的位址。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於

String(Char[])

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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 字元陣列。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於

String(ReadOnlySpan<Char>)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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*)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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*

指向一個由 8 位元有符號整數組成的 null 終端陣列的指標。 整數在Windows上使用現行系統碼頁編碼(稱為 CP_ACP)解讀,非Windows則以 UTF-8 編碼方式解讀。

屬性

例外狀況

valuenull

假設 在 ANSI 編碼下,無法用 Stringvalue 初始化 的新value實例。

新字串的初始化長度由 的 value空終止特徵決定,無法分配。

value 指定一個無效的地址。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於

String(Char, Int32)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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 小於零。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於

String(Char*, Int32, Int32)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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 的位址。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於

String(Char[], Int32, Int32)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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 中的項目數。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於

String(SByte*, Int32, Int32)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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 位元有號整數陣列的指標。 整數在Windows上使用現行系統碼頁編碼(稱為 CP_ACP)解讀,非Windows則以 UTF-8 編碼方式解讀。

startIndex
Int32

起始位置。value

length
Int32

裡面可用的 sbytes value 數量。

屬性

例外狀況

valuenull

startIndexlength 小於零。

-或-

所指定的 value + startIndex 位址對目前平台來說過大;也就是說,位址計算超出了範圍。

-或-

新字串的初始化長度太長,無法分配。

value + startIndex 指定的位址小於 64K。

-或-

假設 在 ANSI 編碼下,無法用 Stringvalue 初始化 的新value實例。

value, , startIndexlength 並共同指定一個無效地址。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於

String(SByte*, Int32, Int32, Encoding)

來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
String.cs
來源:
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

裡面可用的 sbytes value 數量。

enc
Encoding

一個指定如何編碼 的 value 陣列的物件。 若 encnull,則假設採用 ANSI 編碼。

屬性

例外狀況

valuenull

startIndexlength 小於零。

-或-

所指定的 value + startIndex 位址對目前平台來說過大;也就是說,位址計算超出了範圍。

-或-

新字串的初始化長度太長,無法分配。

value + startIndex 指定的位址小於 64K。

-或-

假設 以 編碼,假設 依 所指定String編碼,新的 實value例無法使用 。valueenc

value, , startIndexlength 並共同指定一個無效地址。

備註

Note

關於此及其他 String 建構器超載的範例及完整使用資訊,請參閱 String 建構器摘要。

適用於