共用方式為


StringBuilder.Append 方法

定義

將指定物件的字串表示附加於此實例。

多載

名稱 Description
Append(Rune)
Append(StringBuilder)

將指定字串建構器的字串表示附加到此實例。

Append(StringBuilder+AppendInterpolatedStringHandler)

將指定的插值字串附加到此實例中。

Append(UInt16)

在此實例中附加指定 16 位元無符號整數的字串表示。

Append(UInt64)

在此實例中附加指定 64 位元無符號整數的字串表示。

Append(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

會以指定格式將指定的插值字串附加到此實例。

Append(Char*, Int32)

在此實例中附加一個從指定位址開始的 Unicode 字元陣列。

Append(String)

將指定字串的副本附加到此實例。

Append(Char[], Int32, Int32)

將指定 Unicode 子陣列的字串表示附加到此實例。

Append(String, Int32, Int32)

在此實例中附加指定子字串的副本。

Append(StringBuilder, Int32, Int32)

在此實例中附加指定字串建構器中的子字串副本。

Append(Char, Int32)

在此實例中附加指定數量的 Unicode 字串表示副本。

Append(Single)

在此實例中附加指定的單精度浮點數字串表示。

Append(UInt32)

在此實例中附加指定 32 位元無符號整數的字串表示。

Append(ReadOnlySpan<Char>)

在此實例中附加指定唯讀字元區間的字串表示。

Append(SByte)

在此實例中附加指定 8 位元有符號整數的字串表示。

Append(Boolean)

將指定布林值的字串表示附加於此實例。

Append(Byte)

在此實例中附加指定 8 位元無符號整數的字串表示。

Append(Char)

將指定 Char 物件的字串表示附加於此實例。

Append(Decimal)

在此實例中附加指定十進位數的字串表示。

Append(Double)

在此實例中附加指定的雙精度浮點數字串表示。

Append(Char[])

將指定陣列中 Unicode 字元的字串表示附加到此實例。

Append(Int32)

在此實例中附加指定 32 位元有符號整數的字串表示。

Append(Int64)

在此實例中附加指定 64 位元有符號整數的字串表示。

Append(Object)

將指定物件的字串表示附加於此實例。

Append(ReadOnlyMemory<Char>)

將指定唯讀字元記憶體區域的字串表示附加於此實例。

Append(Int16)

在此實例中附加指定16位元有符號整數的字串表示。

Append(Rune)

public:
 System::Text::StringBuilder ^ Append(System::Text::Rune value);
public System.Text.StringBuilder Append(System.Text.Rune value);
member this.Append : System.Text.Rune -> System.Text.StringBuilder
Public Function Append (value As Rune) As StringBuilder

參數

value
Rune

傳回

適用於

Append(StringBuilder)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定字串建構器的字串表示附加到此實例。

public:
 System::Text::StringBuilder ^ Append(System::Text::StringBuilder ^ value);
public System.Text.StringBuilder Append(System.Text.StringBuilder? value);
public System.Text.StringBuilder Append(System.Text.StringBuilder value);
member this.Append : System.Text.StringBuilder -> System.Text.StringBuilder
Public Function Append (value As StringBuilder) As StringBuilder

參數

value
StringBuilder

要附上弦組。

傳回

在完成附加操作後,會參考此實例。

適用於

Append(StringBuilder+AppendInterpolatedStringHandler)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定的插值字串附加到此實例中。

public:
 System::Text::StringBuilder ^ Append(System::Text::StringBuilder::AppendInterpolatedStringHandler % handler);
public System.Text.StringBuilder Append(ref System.Text.StringBuilder.AppendInterpolatedStringHandler handler);
member this.Append : AppendInterpolatedStringHandler -> System.Text.StringBuilder
Public Function Append (ByRef handler As StringBuilder.AppendInterpolatedStringHandler) As StringBuilder

參數

handler
StringBuilder.AppendInterpolatedStringHandler

插值字串要加。

傳回

在附加操作完成後,會參考此實例。

適用於

Append(UInt16)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中附加指定 16 位元無符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(System::UInt16 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(ushort value);
[<System.CLSCompliant(false)>]
member this.Append : uint16 -> System.Text.StringBuilder
Public Function Append (value As UShort) As StringBuilder

參數

value
UInt16

要加的價值。

傳回

在附加操作完成後,會參考此實例。

屬性

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(UInt16) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of a 16-bit unsigned integer: ");
sb.Append(UInt16.MinValue).Append(" to ").Append(UInt16.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
//       The range of a 16-bit unsigned integer: 0 to 65535
let sb = StringBuilder "The range of a 16-bit unsigned integer: "
sb.Append(UInt16.MinValue).Append(" to ").Append UInt16.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The range of a 16-bit unsigned integer: 0 to 65535
Dim sb As New System.Text.StringBuilder("The range of a 16-bit unsigned integer: ")
sb.Append(UInt16.MinValue).Append(" to ").Append(UInt16.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
'       The range of a 16-bit unsigned integer: 0 to 65535

Append(UInt16) 方法呼叫 該 UInt16.ToString(IFormatProvider) 方法以取得 的 value字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(UInt64)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中附加指定 64 位元無符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(System::UInt64 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(ulong value);
[<System.CLSCompliant(false)>]
member this.Append : uint64 -> System.Text.StringBuilder
Public Function Append (value As ULong) As StringBuilder

參數

value
UInt64

要加的價值。

傳回

在附加操作完成後,會參考此實例。

屬性

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(UInt64) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of a 64-bit unsigned integer: ");
sb.Append(UInt64.MinValue).Append(" to ").Append(UInt64.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
//       The range of a 64-bit unsigned integer: 0 to 18446744073709551615
let sb = StringBuilder "The range of a 64-bit unsigned integer: "
sb.Append(UInt64.MinValue).Append(" to ").Append UInt64.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The range of a 64-bit unsigned integer: 0 to 18446744073709551615
Dim sb As New System.Text.StringBuilder("The range of a 64-bit unsigned integer: ")
sb.Append(UInt64.MinValue).Append(" to ").Append(UInt64.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
'       The range of a 64-bit unsigned integer: 0 to 18446744073709551615

Append(UInt64) 方法呼叫 方法 UInt64.ToString(IFormatProvider) 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

會以指定格式將指定的插值字串附加到此實例。

public:
 System::Text::StringBuilder ^ Append(IFormatProvider ^ provider, System::Text::StringBuilder::AppendInterpolatedStringHandler % handler);
public System.Text.StringBuilder Append(IFormatProvider? provider, ref System.Text.StringBuilder.AppendInterpolatedStringHandler handler);
member this.Append : IFormatProvider * AppendInterpolatedStringHandler -> System.Text.StringBuilder
Public Function Append (provider As IFormatProvider, ByRef handler As StringBuilder.AppendInterpolatedStringHandler) As StringBuilder

參數

provider
IFormatProvider

一個提供特定文化格式資訊的物件。

handler
StringBuilder.AppendInterpolatedStringHandler

插值字串要加。

傳回

在附加操作完成後,會參考此實例。

適用於

Append(Char*, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

符合 CLS 規範替代方案
System.Text.StringBuilder.Append(Char[], Int32, Int32)

在此實例中附加一個從指定位址開始的 Unicode 字元陣列。

public:
 System::Text::StringBuilder ^ Append(char* value, int valueCount);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public System.Text.StringBuilder Append(char* value, int valueCount);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(char* value, int valueCount);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
member this.Append : nativeptr<char> * int -> System.Text.StringBuilder
[<System.CLSCompliant(false)>]
member this.Append : nativeptr<char> * int -> System.Text.StringBuilder

參數

value
Char*

指向一組字元的指標。

valueCount
Int32

陣列中的字元數。

傳回

在附加操作完成後,會參考此實例。

屬性

例外狀況

valueCount 小於零。

-或-

擴大此實例的值將超過 MaxCapacity

value 是一個空指標。

備註

此方法會 valueCount 將從位址 value 開始的字元附加到目前的實例。

Append(Char*, Int32) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以在現有參考上呼叫方法或屬性,且不必將回傳值指派給物件 StringBuilder

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

適用於

Append(String)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定字串的副本附加到此實例。

public:
 System::Text::StringBuilder ^ Append(System::String ^ value);
public System.Text.StringBuilder Append(string value);
public System.Text.StringBuilder Append(string? value);
member this.Append : string -> System.Text.StringBuilder
Public Function Append (value As String) As StringBuilder

參數

value
String

要加的線。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(String) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

bool flag = false;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The value of the flag is ").Append(flag).Append(".");
Console.WriteLine(sb.ToString());
// The example displays the following output:
//       The value of the flag is False.
let flag = false
let sb = StringBuilder()
sb.Append("The value of the flag is ").Append(flag).Append "." |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The value of the flag is False.
Dim flag As Boolean = false
Dim sb As New System.Text.StringBuilder
sb.Append("The value of the flag is ").Append(flag).Append(".")
Console.WriteLine(sb.ToString())
' The example displays the following output:
'       The value of the flag is False.

value 為 , null則不作任何變更。

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Char[], Int32, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定 Unicode 子陣列的字串表示附加到此實例。

public:
 System::Text::StringBuilder ^ Append(cli::array <char> ^ value, int startIndex, int charCount);
public System.Text.StringBuilder Append(char[] value, int startIndex, int charCount);
public System.Text.StringBuilder Append(char[]? value, int startIndex, int charCount);
member this.Append : char[] * int * int -> System.Text.StringBuilder
Public Function Append (value As Char(), startIndex As Integer, charCount As Integer) As StringBuilder

參數

value
Char[]

一個字元陣列。

startIndex
Int32

起始位置。value

charCount
Int32

要加上的字元數。

傳回

在附加操作完成後,會參考此實例。

例外狀況

valuenull、 和 startIndexcharCount 都不是零。

charCount 小於零。

-或-

startIndex 小於零。

-或-

startIndex + charCount 大於 的 value長度。

-或-

擴大此實例的值將超過 MaxCapacity

備註

此方法將指定範圍的字 value 元附加到當前實例中。 若 value 和 皆 nullstartIndexcount 為零,則不作任何改變。

Append(Char[], Int32, Int32) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

char[] chars = { 'a', 'b', 'c', 'd', 'e'};
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int startPosition = Array.IndexOf(chars, 'a');
int endPosition = Array.IndexOf(chars, 'c');
if (startPosition >= 0 && endPosition >= 0) {
   sb.Append("The array from positions ").Append(startPosition).
             Append(" to ").Append(endPosition).Append(" contains ").
             Append(chars, startPosition, endPosition + 1).Append(".");
   Console.WriteLine(sb);
}             
// The example displays the following output:
//       The array from positions 0 to 2 contains abc.
let chars = [| 'a'; 'b'; 'c'; 'd'; 'e' |]
let sb = StringBuilder()
let startPosition = Array.IndexOf(chars, 'a')
let endPosition = Array.IndexOf(chars, 'c')

if startPosition >= 0 && endPosition >= 0 then
    sb
        .Append("The array from positions ")
        .Append(startPosition)
        .Append(" to ")
        .Append(endPosition)
        .Append(" contains ")
        .Append(chars, startPosition, endPosition + 1)
        .Append "."
    |> ignore

    printfn $"{sb}"
// The example displays the following output:
//       The array from positions 0 to 2 contains abc.
Dim chars() As Char = { "a"c, "b"c, "c"c, "d"c, "e"c}
Dim sb As New System.Text.StringBuilder()
Dim startPosition As Integer = Array.IndexOf(chars, "a"c)
Dim endPosition As Integer = Array.IndexOf(chars, "c"c)
If startPosition >= 0 AndAlso endPosition >= 0 Then
   sb.Append("The array from positions ").Append(startPosition).
             Append(" to ").Append(endPosition).Append(" contains ").
             Append(chars, startPosition, endPosition + 1).Append(".")
   Console.WriteLine(sb)
End If             
' The example displays the following output:
'       The array from positions 0 to 2 contains abc.

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(String, Int32, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定子字串的副本。

public:
 System::Text::StringBuilder ^ Append(System::String ^ value, int startIndex, int count);
public System.Text.StringBuilder Append(string value, int startIndex, int count);
public System.Text.StringBuilder Append(string? value, int startIndex, int count);
member this.Append : string * int * int -> System.Text.StringBuilder
Public Function Append (value As String, startIndex As Integer, count As Integer) As StringBuilder

參數

value
String

包含要附加的子字串的字串。

startIndex
Int32

子串在 value中的起始位置。

count
Int32

要加入的字元 value 數量。

傳回

在附加操作完成後,會參考此實例。

例外狀況

valuenull、 和 startIndexcount 都不是零。

count 不到零。

-或-

startIndex 不到零。

-或-

startIndex + count 大於 的 value長度。

-或-

擴大此實例的值將超過 MaxCapacity

備註

此方法將指定範圍的字 value 元附加到當前實例中。 若 value 和 皆 nullstartIndexcount 為零,則不作任何改變。

Append(String, Int32, Int32) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

string str = "First;George Washington;1789;1797";
int index = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int length = str.IndexOf(';', index);      
sb.Append(str, index, length).Append(" President of the United States: ");
index += length + 1;
length = str.IndexOf(';', index) - index;
sb.Append(str, index, length).Append(", from ");
index += length + 1;
length = str.IndexOf(';', index) - index;
sb.Append(str, index, length).Append(" to ");
index += length + 1;
sb.Append(str, index, str.Length - index);
Console.WriteLine(sb);
// The example displays the following output:
//    First President of the United States: George Washington, from 1789 to 1797
let str = "First;George Washington;1789;1797"
let mutable index = 0
let sb = StringBuilder()
let length = str.IndexOf(';', index)

sb.Append(str, index, length).Append " President of the United States: "
|> ignore

index <- index + length + 1
let length = str.IndexOf(';', index) - index
sb.Append(str, index, length).Append ", from " |> ignore
index <- index + length + 1
let length = str.IndexOf(';', index) - index
sb.Append(str, index, length).Append " to " |> ignore
index <- index + length + 1
sb.Append(str, index, str.Length - index) |> ignore
printfn $"{sb}"
// The example displays the following output:
//    First President of the United States: George Washington, from 1789 to 1797
Dim str As String = "First;George Washington;1789;1797"
Dim index As Integer = 0
Dim sb As New System.Text.StringBuilder()
Dim length As Integer = str.IndexOf(";"c, index)      
sb.Append(str, index, length).Append(" President of the United States: ")
index += length + 1
length = str.IndexOf(";"c, index) - index
sb.Append(str, index, length).Append(", from ")
index += length + 1
length = str.IndexOf(";"c, index) - index
sb.Append(str, index, length).Append(" to ")
index += length + 1
sb.Append(str, index, str.Length - index)
Console.WriteLine(sb)
' The example displays the following output:
'    First President of the United States: George Washington, from 1789 to 1797

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(StringBuilder, Int32, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定字串建構器中的子字串副本。

public:
 System::Text::StringBuilder ^ Append(System::Text::StringBuilder ^ value, int startIndex, int count);
public System.Text.StringBuilder Append(System.Text.StringBuilder? value, int startIndex, int count);
public System.Text.StringBuilder Append(System.Text.StringBuilder value, int startIndex, int count);
member this.Append : System.Text.StringBuilder * int * int -> System.Text.StringBuilder
Public Function Append (value As StringBuilder, startIndex As Integer, count As Integer) As StringBuilder

參數

value
StringBuilder

包含要附加的子字串的字串建構器。

startIndex
Int32

子串在 value中的起始位置。

count
Int32

要加入的字元 value 數量。

傳回

在附加操作完成後,會參考此實例。

適用於

Append(Char, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定數量的 Unicode 字串表示副本。

public:
 System::Text::StringBuilder ^ Append(char value, int repeatCount);
public System.Text.StringBuilder Append(char value, int repeatCount);
member this.Append : char * int -> System.Text.StringBuilder
Public Function Append (value As Char, repeatCount As Integer) As StringBuilder

參數

value
Char

要加上的字元。

repeatCount
Int32

要加 value的次數。

傳回

在附加操作完成後,會參考此實例。

例外狀況

repeatCount 小於零。

-或-

擴大此實例的值將超過 MaxCapacity

記憶體不足。

備註

Append(Char, Int32) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

decimal value = 1346.19m;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).AppendFormat("{0:C2}", value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
//       *****$1,346.19*****
let value = 1346.19m
let sb = StringBuilder()
sb.Append('*', 5).AppendFormat("{0:C2}", value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
//       *****$1,346.19*****
Dim value As Decimal = 1346.19d
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).AppendFormat("{0:C2}", value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
'       *****$1,346.19*****

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Single)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定的單精度浮點數字串表示。

public:
 System::Text::StringBuilder ^ Append(float value);
public System.Text.StringBuilder Append(float value);
member this.Append : single -> System.Text.StringBuilder
Public Function Append (value As Single) As StringBuilder

參數

value
Single

要加的價值。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Single) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

float value = 1034769.47f;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
//       *****1034769.47*****
let value = 1034769.47f
let sb = StringBuilder()
sb.Append('*', 5).Append(value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
//       *****1034769.47*****
Dim value As Single = 1034769.47
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).Append(value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
'       *****1034769.47*****

Append(Single) 方法呼叫 方法 Single.ToString 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(UInt32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中附加指定 32 位元無符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(System::UInt32 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(uint value);
[<System.CLSCompliant(false)>]
member this.Append : uint32 -> System.Text.StringBuilder
Public Function Append (value As UInteger) As StringBuilder

參數

value
UInt32

要加的價值。

傳回

在附加操作完成後,會參考此實例。

屬性

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(UInt32) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of a 32-bit unsigned integer: ");
sb.Append(UInt32.MinValue).Append(" to ").Append(UInt32.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
//       The range of a 32-bit unsigned integer: 0 to 4294967295
let sb = StringBuilder "The range of a 32-bit unsigned integer: "
sb.Append(UInt32.MinValue).Append(" to ").Append UInt32.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The range of a 32-bit unsigned integer: 0 to 4294967295
Dim sb As New System.Text.StringBuilder("The range of a 32-bit unsigned integer: ")
sb.Append(UInt32.MinValue).Append(" to ").Append(UInt32.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
'       The range of a 32-bit unsigned integer: 0 to 4294967295

Append(UInt32)UInt32.ToString方法呼叫 以取得當前文化的value字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(ReadOnlySpan<Char>)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定唯讀字元區間的字串表示。

public:
 System::Text::StringBuilder ^ Append(ReadOnlySpan<char> value);
public System.Text.StringBuilder Append(ReadOnlySpan<char> value);
member this.Append : ReadOnlySpan<char> -> System.Text.StringBuilder
Public Function Append (value As ReadOnlySpan(Of Char)) As StringBuilder

參數

value
ReadOnlySpan<Char>

唯讀字元的 span to append。

傳回

在完成附加操作後,會參考此實例。

適用於

Append(SByte)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中附加指定 8 位元有符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(System::SByte value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Append(sbyte value);
[<System.CLSCompliant(false)>]
member this.Append : sbyte -> System.Text.StringBuilder
Public Function Append (value As SByte) As StringBuilder

參數

value
SByte

要加的價值。

傳回

在附加操作完成後,會參考此實例。

屬性

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(SByte) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of an 8-bit signed integer: ");
sb.Append(SByte.MinValue).Append(" to ").Append(SByte.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
//       The range of an 8-bit unsigned integer: -128 to 127
let sb = StringBuilder "The range of an 8-bit signed integer: "
sb.Append(SByte.MinValue).Append(" to ").Append SByte.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The range of an 8-bit unsigned integer: -128 to 127
Dim sb As New System.Text.StringBuilder("The range of an 8-bit signed integer: ")
sb.Append(SByte.MinValue).Append(" to ").Append(SByte.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
'       The range of an 8-bit unsigned integer: -128 to 127

Append(SByte) 方法呼叫 方法 SByte.ToString(IFormatProvider) 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Boolean)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定布林值的字串表示附加於此實例。

public:
 System::Text::StringBuilder ^ Append(bool value);
public System.Text.StringBuilder Append(bool value);
member this.Append : bool -> System.Text.StringBuilder
Public Function Append (value As Boolean) As StringBuilder

參數

value
Boolean

布林值要附加。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Boolean) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

bool flag = false;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The value of the flag is ").Append(flag).Append(".");
Console.WriteLine(sb.ToString());
// The example displays the following output:
//       The value of the flag is False.
let flag = false
let sb = StringBuilder()
sb.Append("The value of the flag is ").Append(flag).Append "." |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The value of the flag is False.
Dim flag As Boolean = false
Dim sb As New System.Text.StringBuilder
sb.Append("The value of the flag is ").Append(flag).Append(".")
Console.WriteLine(sb.ToString())
' The example displays the following output:
'       The value of the flag is False.

Append(Boolean) 方法呼叫 該 Boolean.ToString() 方法以取得 的 value字串表示。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Byte)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定 8 位元無符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(System::Byte value);
public System.Text.StringBuilder Append(byte value);
member this.Append : byte -> System.Text.StringBuilder
Public Function Append (value As Byte) As StringBuilder

參數

value
Byte

要加的價值。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Byte) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

Byte[] bytes = { 16, 132, 27, 253 };
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var value in bytes)
   sb.Append(value).Append(" ");         

Console.WriteLine("The byte array: {0}", sb.ToString());
// The example displays the following output:
//         The byte array: 16 132 27 253
let bytes = [| 16uy; 132uy; 27uy; 253uy |]
let sb = StringBuilder()

for value in bytes do
    sb.Append(value).Append " " |> ignore

printfn $"The byte array: {sb}"
// The example displays the following output:
//         The byte array: 16 132 27 253
Dim bytes() As Byte = { 16, 132, 27, 253 }
Dim sb As New System.Text.StringBuilder()
For Each value In bytes
   sb.Append(value).Append(" ")         
Next
Console.WriteLine("The byte array: {0}", sb.ToString())
' The example displays the following output:
'         The byte array: 16 132 27 253

Append(Byte) 方法呼叫 方法 ToString(IFormatProvider) 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Char)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定 Char 物件的字串表示附加於此實例。

public:
 System::Text::StringBuilder ^ Append(char value);
public System.Text.StringBuilder Append(char value);
member this.Append : char -> System.Text.StringBuilder
Public Function Append (value As Char) As StringBuilder

參數

value
Char

UTF-16編碼的編碼單元將被附加。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Char) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

string str = "Characters in a string.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var ch in str)
   sb.Append(" '").Append(ch).Append("' ");

Console.WriteLine("Characters in the string:");
Console.WriteLine("  {0}", sb);
// The example displays the following output:
//    Characters in the string:
//       'C'  'h'  'a'  'r'  'a'  'c'  't'  'e'  'r'  's'  ' '  'i'  'n'  ' '  'a'  ' '  's'  't' 'r'  'i'  'n'  'g'  '.'
let str = "Characters in a string."
let sb = StringBuilder()

for ch in str do
    sb.Append(" '").Append(ch).Append "' " |> ignore

printfn "Characters in the string:"
printfn $"  {sb}"
// The example displays the following output:
//    Characters in the string:
//       'C'  'h'  'a'  'r'  'a'  'c'  't'  'e'  'r'  's'  ' '  'i'  'n'  ' '  'a'  ' '  's'  't' 'r'  'i'  'n'  'g'  '.'
Dim str As String = "Characters in a string."
Dim sb As New System.Text.StringBuilder()
For Each ch In str
   sb.Append(" '").Append(ch).Append("' ")
Next
Console.WriteLine("Characters in the string:")
Console.WriteLine("  {0}", sb)
' The example displays the following output:
'    Characters in the string:
'       'C'  'h'  'a'  'r'  'a'  'c'  't'  'e'  'r'  's'  ' '  'i'  'n'  ' '  'a'  ' '  's'  't' 'r'  'i'  'n'  'g'  '.'

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Decimal)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定十進位數的字串表示。

public:
 System::Text::StringBuilder ^ Append(System::Decimal value);
public System.Text.StringBuilder Append(decimal value);
member this.Append : decimal -> System.Text.StringBuilder
Public Function Append (value As Decimal) As StringBuilder

參數

value
Decimal

要加的價值。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Decimal) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

decimal value = 1346.19m;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
//       *****1346.19*****
let value = 1346.19m
let sb = StringBuilder()
sb.Append('*', 5).Append(value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
//       *****1346.19*****
Dim value As Decimal = 1346.19d
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).Append(value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
'       *****1346.19*****

Append(Decimal) 方法呼叫 方法 Decimal.ToString(IFormatProvider) 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Double)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定的雙精度浮點數字串表示。

public:
 System::Text::StringBuilder ^ Append(double value);
public System.Text.StringBuilder Append(double value);
member this.Append : double -> System.Text.StringBuilder
Public Function Append (value As Double) As StringBuilder

參數

value
Double

要加的價值。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Double) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

double value = 1034769.47;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
// The example displays the following output:
//       *****1034769.47*****
let value = 1034769.47
let sb = StringBuilder()
sb.Append('*', 5).Append(value).Append('*', 5) |> ignore
printfn $"{sb}"
// The example displays the following output:
//       *****1034769.47*****
Dim value As Double = 1034769.47
Dim sb As New System.Text.StringBuilder()
sb.Append("*"c, 5).Append(value).Append("*"c, 5)
Console.WriteLine(sb)
' The example displays the following output:
'       *****1034769.47*****

Append(Double) 方法呼叫 方法 Double.ToString(IFormatProvider) 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Char[])

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定陣列中 Unicode 字元的字串表示附加到此實例。

public:
 System::Text::StringBuilder ^ Append(cli::array <char> ^ value);
public System.Text.StringBuilder Append(char[] value);
public System.Text.StringBuilder Append(char[]? value);
member this.Append : char[] -> System.Text.StringBuilder
Public Function Append (value As Char()) As StringBuilder

參數

value
Char[]

要加上的字元陣列。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

此方法會將指定陣列中的所有字元依照出現在 value的順序附加到目前實例。 若 value 為 , null則不作任何變更。

Append(Char[]) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

char[] chars = { 'a', 'e', 'i', 'o', 'u' };
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The characters in the array: ").Append(chars);
Console.WriteLine(sb);
// The example displays the following output:
//      The characters in the array: aeiou
let chars = [| 'a'; 'e'; 'i'; 'o'; 'u' |]
let sb = StringBuilder()
sb.Append("The characters in the array: ").Append chars |> ignore
printfn $"{sb}"
// The example displays the following output:
//      The characters in the array: aeiou
Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c }
Dim sb As New System.Text.StringBuilder()
sb.Append("The characters in the array: ").Append(chars)
Console.WriteLine(sb)
' The example displays the following output:
'      The characters in the array: aeiou

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

適用於

Append(Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定 32 位元有符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(int value);
public System.Text.StringBuilder Append(int value);
member this.Append : int -> System.Text.StringBuilder
Public Function Append (value As Integer) As StringBuilder

參數

value
Int32

要加的價值。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Int32) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

System.Text.StringBuilder sb = new 
       System.Text.StringBuilder("The range of a 32-bit integer: ");
sb.Append(Int32.MinValue).Append(" to ").Append(Int32.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
//       The range of a 32-bit integer: -2147483648 to 2147483647
let sb = StringBuilder "The range of a 32-bit integer: "
sb.Append(Int32.MinValue).Append(" to ").Append Int32.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The range of a 32-bit integer: -2147483648 to 2147483647
Dim sb As New System.Text.StringBuilder("The range of a 32-bit integer: ")
sb.Append(Int32.MinValue).Append(" to ").Append(Int32.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
'       The range of a 32-bit integer: -2147483648 to 2147483647

Append(Int32) 方法呼叫 方法 Int32.ToString(IFormatProvider) 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Int64)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定 64 位元有符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(long value);
public System.Text.StringBuilder Append(long value);
member this.Append : int64 -> System.Text.StringBuilder
Public Function Append (value As Long) As StringBuilder

參數

value
Int64

要加的價值。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Int64) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of a 64-bit integer: ");
sb.Append(Int64.MinValue).Append(" to ").Append(Int64.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
//       The range of a 64-bit integer:  -9223372036854775808 to 9223372036854775807
let sb = StringBuilder "The range of a 64-bit integer: "
sb.Append(Int64.MinValue).Append(" to ").Append Int64.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The range of a 64-bit integer:  -9223372036854775808 to 9223372036854775807
Dim sb As New System.Text.StringBuilder("The range of a 64-bit integer: ")
sb.Append(Int64.MinValue).Append(" to ").Append(Int64.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
'       The range of a 64-bit integer:  -9223372036854775808 to 9223372036854775807

Append(Int64) 方法呼叫 來 Int64.ToString(IFormatProvider) 取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(Object)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定物件的字串表示附加於此實例。

public:
 System::Text::StringBuilder ^ Append(System::Object ^ value);
public System.Text.StringBuilder Append(object value);
public System.Text.StringBuilder Append(object? value);
member this.Append : obj -> System.Text.StringBuilder
Public Function Append (value As Object) As StringBuilder

參數

value
Object

要附加的物件。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Object) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。 它會定義一個 Dog 類別,建立一個 Dog 物件,並呼叫該 Append 方法三次,產生包含狗名稱和品種的字串。

using System;

public class Dog
{
   private string dogBreed;
   private string dogName;
   
   public Dog(string name, string breed)
   {
      this.dogName = name;
      this.dogBreed = breed;
   }
   
   public string Breed {
      get { return this.dogBreed; }
   }
   
   public string Name {
      get { return this.dogName; }
   }
   
   public override string ToString()
   {
      return this.dogName;
   }
}

public class Example
{
   public static void Main()
   {
      Dog dog1 = new Dog("Yiska", "Alaskan Malamute");
      System.Text.StringBuilder sb = new System.Text.StringBuilder();     
      sb.Append(dog1).Append(", Breed: ").Append(dog1.Breed);  
      Console.WriteLine(sb);
   }
}
// The example displays the following output:
//        Yiska, Breed: Alaskan Malamute
open System.Text

type Dog(name: string, breed: string) =
    member _.Name = name
    member _.Breed = breed
    override _.ToString() = name

let dog1 = Dog("Yiska", "Alaskan Malamute")
let sb = StringBuilder()
sb.Append(dog1).Append(", Breed: ").Append dog1.Breed |> printfn "%O"

// The example displays the following output:
//        Yiska, Breed: Alaskan Malamute
Public Class Dog
   Private dogBreed As String
   Private dogName As String
   
   Public Sub New(name As String, breed As String)
      Me.dogName = name
      Me.dogBreed = breed
   End Sub
   
   Public ReadOnly Property Breed As String
      Get
         Return Me.dogBreed
      End Get
   End Property
   
   Public ReadOnly Property Name As String
      Get
         Return Me.dogName
      End Get
   End Property
   
   Public Overrides Function ToString() As String
      Return Me.dogName
   End Function
End Class
   
Module Example
   Public Sub Main()
      Dim dog1 As New Dog("Yiska", "Alaskan Malamute")
      Dim sb As New System.Text.StringBuilder()     
      sb.Append(dog1).Append(", Breed: ").Append(dog1.Breed)  
      Console.WriteLine(sb)
   End Sub
End Module
' The example displays the following output:
'       Yiska, Breed: Alaskan Malamute

Append(Object) 方法呼叫 該 Object.ToString 方法以取得 的 value字串表示。 若 valuenull,則物件不會被 StringBuilder 更改。

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於

Append(ReadOnlyMemory<Char>)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定唯讀字元記憶體區域的字串表示附加於此實例。

public:
 System::Text::StringBuilder ^ Append(ReadOnlyMemory<char> value);
public System.Text.StringBuilder Append(ReadOnlyMemory<char> value);
member this.Append : ReadOnlyMemory<char> -> System.Text.StringBuilder
Public Function Append (value As ReadOnlyMemory(Of Char)) As StringBuilder

參數

value
ReadOnlyMemory<Char>

要附加的唯讀字元記憶體區域。

傳回

在完成附加操作後,會參考此實例。

適用於

Append(Int16)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中附加指定16位元有符號整數的字串表示。

public:
 System::Text::StringBuilder ^ Append(short value);
public System.Text.StringBuilder Append(short value);
member this.Append : int16 -> System.Text.StringBuilder
Public Function Append (value As Short) As StringBuilder

參數

value
Int16

要加的價值。

傳回

在附加操作完成後,會參考此實例。

例外狀況

擴大此實例的值將超過 MaxCapacity

備註

Append(Int16) 方法修改了該類別的現有實例;它不會回傳新的類別實例。 因此,你可以呼叫現有參考的資料或屬性,且不必將回傳值指派給物件 StringBuilder ,如下範例所示。

System.Text.StringBuilder sb = new 
       System.Text.StringBuilder("The range of a 16-bit integer: ");
sb.Append(Int16.MinValue).Append(" to ").Append(Int16.MaxValue);
Console.WriteLine(sb);
// The example displays the following output:
//       The range of a 16-bit integer: -32768 to 32767
let sb = StringBuilder "The range of a 16-bit integer: "
sb.Append(Int16.MinValue).Append(" to ").Append Int16.MaxValue |> ignore
printfn $"{sb}"
// The example displays the following output:
//       The range of a 16-bit integer: -32768 to 32767
Dim sb As New System.Text.StringBuilder("The range of a 16-bit integer: ")
sb.Append(Int16.MinValue).Append(" to ").Append(Int16.MaxValue)
Console.WriteLine(sb)
' The example displays the following output:
'       The range of a 16-bit integer: -32768 to 32767

Append(Int16) 方法呼叫 方法 Int16.ToString(IFormatProvider) 以取得當前文化的 value 字串表示。 要控制 的 value格式化,呼叫 方法 AppendFormat

此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Core 及 .NET Framework 4.0 及後續版本中,當你呼叫StringBuilder(Int32, Int32)建構子實StringBuilder例化物件時,實例的長度和容量StringBuilder都可能超出其MaxCapacity屬性的值。 這種情況尤其可能發生在你呼叫 和 Append(String)AppendFormat(String, Object) 方法來附加小字串時。

另請參閱

適用於