StringBuilder.AppendLine 方法

定義

將預設行結束字元,或是指定字串的複本以及預設行結束字元,附加至這個執行個體的尾端。

多載

AppendLine()

將預設行結束字元附加至目前 StringBuilder 物件的尾端。

AppendLine(String)

將後面接著預設行結束字元的指定字串複本附加至目前的 StringBuilder 物件結尾。

AppendLine(StringBuilder+AppendInterpolatedStringHandler)

將指定的插入字串附加至目前 StringBuilder 物件的結尾,後面接著預設行結束字元。

AppendLine(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

使用指定的格式,後面接著預設行結束字元,將指定的插入字串附加至目前 StringBuilder 物件的結尾。

AppendLine()

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

將預設行結束字元附加至目前 StringBuilder 物件的尾端。

public:
 System::Text::StringBuilder ^ AppendLine();
public System.Text.StringBuilder AppendLine ();
[System.Runtime.InteropServices.ComVisible(false)]
public System.Text.StringBuilder AppendLine ();
member this.AppendLine : unit -> System.Text.StringBuilder
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.AppendLine : unit -> System.Text.StringBuilder
Public Function AppendLine () As StringBuilder

傳回

完成附加作業之後,這個執行個體的參考。

屬性

例外狀況

加大此執行個體的值可能會超過 MaxCapacity

範例

下列範例示範 AppendLine 方法。

// This example demonstrates the StringBuilder.AppendLine()
// method.

using namespace System;
using namespace System::Text;

int main()
{
    StringBuilder^ sb = gcnew StringBuilder;
    String^ line = L"A line of text.";
    int number = 123;

    // Append two lines of text.
    sb->AppendLine( L"The first line of text." );
    sb->AppendLine( line );

    // Append a new line, an empty string, and a null cast as a string.
    sb->AppendLine();
    sb->AppendLine( L"" );
    sb->AppendLine( L"" );

    // Append the non-string value, 123, and two new lines.
    sb->Append( number )->AppendLine()->AppendLine();

    // Append two lines of text.
    sb->AppendLine( line );
    sb->AppendLine( L"The last line of text." );

    // Convert the value of the StringBuilder to a string and display the string.
    Console::WriteLine( sb );

    return 0;
}

/*
This example produces the following results:

The first line of text.
A line of text.



123

A line of text.
The last line of text.
*/
// This example demonstrates the StringBuilder.AppendLine()
// method.

using System;
using System.Text;

class Sample
{
    public static void Main()
    {
    StringBuilder sb = new StringBuilder();
    string        line = "A line of text.";
    int           number = 123;

// Append two lines of text.
    sb.AppendLine("The first line of text.");
    sb.AppendLine(line);

// Append a new line, an empty string, and a null cast as a string.
    sb.AppendLine();
    sb.AppendLine("");
    sb.AppendLine((string)null);

// Append the non-string value, 123, and two new lines.
    sb.Append(number).AppendLine().AppendLine();

// Append two lines of text.
    sb.AppendLine(line);
    sb.AppendLine("The last line of text.");

// Convert the value of the StringBuilder to a string and display the string.
    Console.WriteLine(sb.ToString());
    }
}
/*
This example produces the following results:

The first line of text.
A line of text.



123

A line of text.
The last line of text.
*/
// This example demonstrates the StringBuilder.AppendLine()
// method.

open System.Text

let sb = StringBuilder()
let line = "A line of text."
let number = 123

// Append two lines of text.
sb.AppendLine "The first line of text." |> ignore
sb.AppendLine line |> ignore

// Append a new line, an empty string, and a null cast as a string.
sb.AppendLine() |> ignore
sb.AppendLine "" |> ignore
sb.AppendLine Unchecked.defaultof<string> |> ignore

// Append the non-string value, 123, and two new lines.
sb.Append(number).AppendLine().AppendLine() |> ignore

// Append two lines of text.
sb.AppendLine line |> ignore
sb.AppendLine "The last line of text." |> ignore

// Convert the value of the StringBuilder to a string and display the string.
printfn $"{sb}"

// This example produces the following results:
//       The first line of text.
//       A line of text.
//
//
//
//       123
//
//       A line of text.
//       The last line of text.
' This example demonstrates the StringBuilder.AppendLine() 
' method.
Imports System.Text

Class Sample
   Public Shared Sub Main()
      Dim sb As New StringBuilder()
      Dim line As String = "A line of text."
      Dim number As Integer = 123
      
      ' Append two lines of text.
      sb.AppendLine("The first line of text.")
      sb.AppendLine(line)
      
      ' Append a new line, an empty string, and a null cast as a string.
      sb.AppendLine()
      sb.AppendLine("")
      sb.AppendLine(CStr(Nothing))
      
      ' Append the non-string value, 123, and two new lines.
      sb.Append(number).AppendLine().AppendLine()
      
      ' Append two lines of text.
      sb.AppendLine(line)
      sb.AppendLine("The last line of text.")
      
      ' Convert the value of the StringBuilder to a string and display the string.
      Console.WriteLine(sb.ToString())
   End Sub
End Class
'
'This example produces the following results:
'
'The first line of text.
'A line of text.
'
'
'
'123
'
'A line of text.
'The last line of text.

備註

預設行結束字元是 屬性的 Environment.NewLine 目前值。

視需要調整此實例的容量。

給呼叫者的注意事項

在 .NET Core 和 .NET Framework 4.0 和更新版本中,當您藉由呼叫 StringBuilder(Int32, Int32) 建構函式來具現化 StringBuilder 物件時,實例的 StringBuilder 長度和容量都可以成長超過其 MaxCapacity 屬性的值。 當您呼叫 Append(String)AppendFormat(String, Object) 方法來附加小型字串時,就會發生此情況。

另請參閱

適用於

AppendLine(String)

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

將後面接著預設行結束字元的指定字串複本附加至目前的 StringBuilder 物件結尾。

public:
 System::Text::StringBuilder ^ AppendLine(System::String ^ value);
public System.Text.StringBuilder AppendLine (string value);
public System.Text.StringBuilder AppendLine (string? value);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Text.StringBuilder AppendLine (string value);
member this.AppendLine : string -> System.Text.StringBuilder
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.AppendLine : string -> System.Text.StringBuilder
Public Function AppendLine (value As String) As StringBuilder

參數

value
String

要附加的字串。

傳回

完成附加作業之後,這個執行個體的參考。

屬性

例外狀況

加大此執行個體的值可能會超過 MaxCapacity

備註

預設行結束字元是 屬性的 Environment.NewLine 目前值。

視需要調整此實例的容量。

給呼叫者的注意事項

在 .NET Core 和 .NET Framework 4.0 和更新版本中,當您藉由呼叫 StringBuilder(Int32, Int32) 建構函式來具現化 StringBuilder 物件時,實例的 StringBuilder 長度和容量都可以成長超過其 MaxCapacity 屬性的值。 當您呼叫 Append(String)AppendFormat(String, Object) 方法來附加小型字串時,就會發生此情況。

另請參閱

適用於

AppendLine(StringBuilder+AppendInterpolatedStringHandler)

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

將指定的插入字串附加至目前 StringBuilder 物件的結尾,後面接著預設行結束字元。

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

參數

handler
StringBuilder.AppendInterpolatedStringHandler

要附加的插入字串。

傳回

完成附加作業之後,這個執行個體的參考。

適用於

AppendLine(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

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

使用指定的格式,後面接著預設行結束字元,將指定的插入字串附加至目前 StringBuilder 物件的結尾。

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

參數

provider
IFormatProvider

物件,提供特定文化特性格式資訊。

handler
StringBuilder.AppendInterpolatedStringHandler

要附加的插入字串。

傳回

完成附加作業之後,這個執行個體的參考。

適用於