StringBuilder.AppendLine Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Lägger till standardlinjeavgränsaren, eller en kopia av en angiven sträng och standardradsavgränsaren, i slutet av den här instansen.
Överlagringar
| Name | Description |
|---|---|
| AppendLine() |
Lägger till standardradsavgränsaren i slutet av det aktuella StringBuilder objektet. |
| AppendLine(String) |
Lägger till en kopia av den angivna strängen följt av standardradsavgränsaren i slutet av det aktuella StringBuilder objektet. |
AppendLine()
Lägger till standardradsavgränsaren i slutet av det aktuella StringBuilder objektet.
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
Returer
En referens till den här instansen när tilläggsåtgärden har slutförts.
- Attribut
Undantag
Om värdet för den här instansen förstoras skulle det överstiga MaxCapacity.
Exempel
I följande exempel visas AppendLine metoden.
// 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.
Kommentarer
Standardradsavgränsaren är det aktuella värdet för Environment.NewLine egenskapen.
Kapaciteten för den här instansen justeras efter behov.
Anteckningar till anropare
När du i .NET Core och i .NET Framework 4.0 och senare versioner instansierar objektet StringBuilder genom att anropa konstruktorn StringBuilder(Int32, Int32) kan både längden och kapaciteten för instansen StringBuilder växa utöver värdet för dess egenskap MaxCapacity. Detta kan inträffa särskilt när du anropar Append(String) metoderna och AppendFormat(String, Object) för att lägga till små strängar.
Se även
Gäller för
AppendLine(String)
Lägger till en kopia av den angivna strängen följt av standardradsavgränsaren i slutet av det aktuella StringBuilder objektet.
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
Parametrar
- value
- String
Strängen som ska läggas till.
Returer
En referens till den här instansen när tilläggsåtgärden har slutförts.
- Attribut
Undantag
Om värdet för den här instansen förstoras skulle det överstiga MaxCapacity.
Kommentarer
Standardradsavgränsaren är det aktuella värdet för Environment.NewLine egenskapen.
Kapaciteten för den här instansen justeras efter behov.
Anteckningar till anropare
När du i .NET Core och i .NET Framework 4.0 och senare versioner instansierar objektet StringBuilder genom att anropa konstruktorn StringBuilder(Int32, Int32) kan både längden och kapaciteten för instansen StringBuilder växa utöver värdet för dess egenskap MaxCapacity. Detta kan inträffa särskilt när du anropar Append(String) metoderna och AppendFormat(String, Object) för att lägga till små strängar.