C# StringBuilder Append and AppendLine



In this source code example, we will demonstrate the usage of Append and AppendLine methods in C# with examples.

The Append method appends the string representation of a specified object to the builder. 

The AppendLine method appends the default line terminator to the end of the current StringBuilder object.

C# StringBuilder Append and AppendLine

The example builds a string using Append and AppendLine methods.
using System;
using System.Text;

class StringBuilderExample {
  static void Main() {
        var builder= new StringBuilder("Source");
        
        builder.Append(" Code ");
        builder.Append("Examples");
        
        builder.AppendLine();
        
        builder.AppendLine("SourceCodeExamples");
        builder.Append("Programming examples");
        
        Console.WriteLine(builder);
  }
}

Output:

Source Code Examples

SourceCodeExamples

Programming examples

Comments