Поделиться через


StringBuilder.AppendLine Метод

Определение

Добавляет конечный элемент строки по умолчанию или копию указанной строки и конца строки по умолчанию в конец этого экземпляра.

Перегрузки

Имя Описание
AppendLine()

Добавляет конечный элемент строки по умолчанию к концу текущего StringBuilder объекта.

AppendLine(String)

Добавляет копию указанной строки, за которой следует терминатор строки по умолчанию к концу текущего StringBuilder объекта.

AppendLine(StringBuilder+AppendInterpolatedStringHandler)

Добавляет указанную интерполированную строку, за которой следует конечный элемент строки по умолчанию в конец текущего объекта StringBuilder.

AppendLine(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

Добавляет указанную интерполированную строку с помощью указанного формата, за которым следует конечный элемент строки по умолчанию, к концу текущего объекта StringBuilder.

AppendLine()

Исходный код:
StringBuilder.cs
Исходный код:
StringBuilder.cs
Исходный код:
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 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 объекта путем вызова StringBuilder(Int32, Int32) конструктора длина и емкость StringBuilder экземпляра могут превышать значение его MaxCapacity свойства. Это может произойти особенно при вызове Append(String) и AppendFormat(String, Object) методах для добавления небольших строк.

См. также раздел

Применяется к

AppendLine(String)

Исходный код:
StringBuilder.cs
Исходный код:
StringBuilder.cs
Исходный код:
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 объекта путем вызова StringBuilder(Int32, Int32) конструктора длина и емкость StringBuilder экземпляра могут превышать значение его MaxCapacity свойства. Это может произойти особенно при вызове Append(String) и AppendFormat(String, Object) методах для добавления небольших строк.

См. также раздел

Применяется к

AppendLine(StringBuilder+AppendInterpolatedStringHandler)

Исходный код:
StringBuilder.cs
Исходный код:
StringBuilder.cs
Исходный код:
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.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

Интерполированная строка для добавления.

Возвращаемое значение

Ссылка на этот экземпляр после завершения операции добавления.

Применяется к