StringBuilder.AppendLine Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Adiciona o terminador de linha por defeito, ou uma cópia de uma string especificada e o terminador de linha por defeito, ao final desta instância.
Sobrecargas
| Name | Description |
|---|---|
| AppendLine() |
Adiciona o terminador de linha por defeito ao final do objeto atual StringBuilder . |
| AppendLine(String) |
Adiciona uma cópia da string especificada seguida pelo terminador de linha padrão ao final do objeto atual StringBuilder . |
AppendLine()
Adiciona o terminador de linha por defeito ao final do objeto atual 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
Devoluções
Uma referência a esta instância após a conclusão da operação de anexação.
- Atributos
Exceções
Aumentar o valor desta instância excederia MaxCapacity.
Exemplos
O exemplo seguinte demonstra o AppendLine método.
// 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.
Observações
O terminador de linha padrão é o valor atual da Environment.NewLine propriedade.
A capacidade desta instância é ajustada conforme necessário.
Notas para Chamadores
No .NET Core e no .NET Framework 4.0 e versões posteriores, quando se instancia o objeto StringBuilder chamando o construtor StringBuilder(Int32, Int32), tanto o comprimento como a capacidade da instância StringBuilder podem crescer para além do valor da sua propriedade MaxCapacity. Isto pode acontecer especialmente quando chamas os Append(String) métodos e AppendFormat(String, Object) para acrescentar pequenas cadeias.
Ver também
Aplica-se a
AppendLine(String)
Adiciona uma cópia da string especificada seguida pelo terminador de linha padrão ao final do objeto atual StringBuilder .
public:
System::Text::StringBuilder ^ AppendLine(System::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
Parâmetros
- value
- String
O fio para anexar.
Devoluções
Uma referência a esta instância após a conclusão da operação de anexação.
- Atributos
Exceções
Aumentar o valor desta instância excederia MaxCapacity.
Observações
O terminador de linha padrão é o valor atual da Environment.NewLine propriedade.
A capacidade desta instância é ajustada conforme necessário.
Notas para Chamadores
No .NET Core e no .NET Framework 4.0 e versões posteriores, quando se instancia o objeto StringBuilder chamando o construtor StringBuilder(Int32, Int32), tanto o comprimento como a capacidade da instância StringBuilder podem crescer para além do valor da sua propriedade MaxCapacity. Isto pode acontecer especialmente quando chamas os Append(String) métodos e AppendFormat(String, Object) para acrescentar pequenas cadeias.