String 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 String 類別的新執行個體。
多載
String(Char*) |
將 String 類別的新執行個體初始化為 Unicode 字元陣列的指定指標所指示的值。 |
String(Char[]) |
將 String 類別新執行個體初始化為所指定字元陣列中指出的 Unicode 字元。 |
String(ReadOnlySpan<Char>) |
將 String 類別新執行個體初始化為所指定唯讀範圍中指出的 Unicode 字元。 |
String(SByte*) |
將 String 類別的新執行個體初始化為 8 位元帶正負號整數 (Signed Integer) 陣列的指標所指示的值。 |
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 的詳細資訊,請參閱 String 建構函式的補充 API 備註。
String(Char*)
- 來源:
- 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*
Unicode 字元之 Null 終端陣列的指標
- 屬性
例外狀況
目前的處理序沒有讀取所有定址字元的權限。
value
指定包含無效 Unicode 字元的陣列,或 value
指定小於 64000 的位址。
備註
注意
如需這個和其他建構函式多載的範例和完整的 String
使用資訊,請參閱建 String 構函式摘要。
適用於
String(Char[])
- 來源:
- 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 字元陣列。
備註
注意
如需這個和其他建構函式多載的範例和完整的 String
使用資訊,請參閱建 String 構函式摘要。
適用於
String(ReadOnlySpan<Char>)
- 來源:
- 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
重要
此 API 不符合 CLS 規範。
將 String 類別的新執行個體初始化為 8 位元帶正負號整數 (Signed Integer) 陣列的指標所指示的值。
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
初始化 String 的新執行個體,假設 value
是 ANSI 編碼。
要初始化的新字串長度,由 value
之 null 結束字元所決定,該長度太長而無法配置。
value
指定了無效的位址。
備註
注意
如需這個和其他建構函式多載的範例和完整的 String
使用資訊,請參閱建 String 構函式摘要。
適用於
String(Char, Int32)
- 來源:
- 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
小於零。
備註
注意
如需這個和其他建構函式多載的範例和完整的 String
使用資訊,請參閱建 String 構函式摘要。
適用於
String(Char*, Int32, Int32)
- 來源:
- 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
內要使用的字元數。
- 屬性
例外狀況
startIndex
或 length
小於零、value
+ startIndex
導致指標溢位,或目前的處理序沒有所有定址字元的讀取權限。
value
指定包含無效 Unicode 字元的陣列,或 value
+ startIndex
指定小於 64000 的位址。
備註
注意
如需這個和其他建構函式多載的範例和完整的 String
使用資訊,請參閱建 String 構函式摘要。
適用於
String(Char[], Int32, Int32)
- 來源:
- 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
內要使用的字元數。
例外狀況
value
為 null
。
備註
注意
如需這個和其他建構函式多載的範例和完整的 String
使用資訊,請參閱建 String 構函式摘要。
適用於
String(SByte*, Int32, Int32)
- 來源:
- 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
參數
- startIndex
- Int32
開始位置在 value
內。
- length
- Int32
value
內要使用的字元數。
- 屬性
例外狀況
value
為 null
。
startIndex
或 length
小於零。
-或-
value
+ startIndex
指定的位址對於目前的平台而言太大,也就是位址計算溢位。
-或-
要初始化的新字串長度太大而無法配置。
value
、startIndex
和 length
共同指定了無效的位址。
備註
注意
如需這個和其他建構函式多載的範例和完整的 String
使用資訊,請參閱建 String 構函式摘要。
適用於
String(SByte*, Int32, Int32, Encoding)
- 來源:
- String.cs
- 來源:
- String.cs
- 來源:
- 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 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應