StringBuilder.AppendLine 方法

定义

将默认的行终止符(或指定字符串的副本和默认的行终止符)追加到此实例的末尾。

重载

AppendLine()

将默认的行终止符追加到当前 StringBuilder 对象的末尾。

AppendLine(String)

将后面跟有默认行终止符的指定字符串的副本追加到当前 StringBuilder 对象的末尾。

AppendLine(StringBuilder+AppendInterpolatedStringHandler)

将指定的内插字符串后跟默认行终止符追加到当前 StringBuilder 对象的末尾。

AppendLine(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

使用指定格式的指定内插字符串(后跟默认行终止符)追加到当前 StringBuilder 对象的末尾。

AppendLine()

Source:
StringBuilder.cs
Source:
StringBuilder.cs
Source:
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)

Source:
StringBuilder.cs
Source:
StringBuilder.cs
Source:
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)

Source:
StringBuilder.cs
Source:
StringBuilder.cs
Source:
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)

Source:
StringBuilder.cs
Source:
StringBuilder.cs
Source:
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

要追加的内插字符串。

返回

完成追加操作后对此实例的引用。

适用于