StringBuilder.AppendLine Método

Definición

Anexa el terminador de línea predeterminado, o una copia de una cadena especificada y el terminador de línea predeterminado, al final de esta instancia.

Sobrecargas

AppendLine()

Anexa el terminador de línea predeterminado al final del objeto StringBuilder actual.

AppendLine(String)

Anexa una copia de la cadena especificada seguida del terminador de línea predeterminado al final del objeto StringBuilder actual.

AppendLine(StringBuilder+AppendInterpolatedStringHandler)

Anexa la cadena interpolada especificada seguida del terminador de línea predeterminado al final del objeto StringBuilder actual.

AppendLine(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

Anexa la cadena interpolada especificada con el formato especificado, seguido del terminador de línea predeterminado, al final del objeto StringBuilder actual.

AppendLine()

Anexa el terminador de línea predeterminado al final del objeto StringBuilder actual.

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

Devoluciones

StringBuilder

Referencia a esta instancia después de que se complete la operación de anexado.

Atributos

Excepciones

Si se amplía el valor de esta instancia, se superará MaxCapacity.

Ejemplos

En el siguiente ejemplo se muestra el AppendLine método.

// 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.
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.

Comentarios

El terminador de línea predeterminado es el valor actual de la Environment.NewLine propiedad .

La capacidad de esta instancia se ajusta según sea necesario.

Notas a los autores de las llamadas

En .NET Core y en .NET Framework 4.0 y versiones posteriores, cuando se crea una instancia del objeto mediante una llamada al constructor, la longitud y la capacidad de la instancia pueden crecer más allá del valor de su StringBuilder StringBuilder(Int32, Int32) StringBuilder MaxCapacity propiedad. Esto puede ocurrir especialmente cuando se llama a los Append(String) AppendFormat(String, Object) métodos y para anexar cadenas pequeñas.

Consulte también

Se aplica a

AppendLine(String)

Anexa una copia de la cadena especificada seguida del terminador de línea predeterminado al final del objeto StringBuilder actual.

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

Parámetros

value
String

Cadena que se va a anexar.

Devoluciones

StringBuilder

Referencia a esta instancia después de que se complete la operación de anexado.

Atributos

Excepciones

Si se amplía el valor de esta instancia, se superará MaxCapacity.

Comentarios

El terminador de línea predeterminado es el valor actual de la Environment.NewLine propiedad .

La capacidad de esta instancia se ajusta según sea necesario.

Notas a los autores de las llamadas

En .NET Core y en .NET Framework 4.0 y versiones posteriores, cuando se crea una instancia del objeto mediante una llamada al constructor, la longitud y la capacidad de la instancia pueden crecer más allá del valor de su StringBuilder StringBuilder(Int32, Int32) StringBuilder MaxCapacity propiedad. Esto puede ocurrir especialmente cuando se llama a los Append(String) AppendFormat(String, Object) métodos y para anexar cadenas pequeñas.

Consulte también

Se aplica a

AppendLine(StringBuilder+AppendInterpolatedStringHandler)

Anexa la cadena interpolada especificada seguida del terminador de línea predeterminado al final del objeto StringBuilder actual.

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

Parámetros

handler
StringBuilder.AppendInterpolatedStringHandler

Cadena interpolada que se anexará.

Devoluciones

StringBuilder

Referencia a esta instancia después de que se complete la operación de anexado.

Se aplica a

AppendLine(IFormatProvider, StringBuilder+AppendInterpolatedStringHandler)

Anexa la cadena interpolada especificada con el formato especificado, seguido del terminador de línea predeterminado, al final del objeto StringBuilder actual.

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

Parámetros

provider
IFormatProvider

Objeto que proporciona información de formato específica de la referencia cultural.

handler
StringBuilder.AppendInterpolatedStringHandler

Cadena interpolada que se anexará.

Devoluciones

StringBuilder

Referencia a esta instancia después de que se complete la operación de anexado.

Se aplica a