Append to StringBuilder in C# with a new line on the end


The AppendLine() method appends the content and add a new line on the end.

Firstly, set the StringBuilder −

StringBuilder str = new StringBuilder();

Use AppendLine() −

str.AppendLine("Accessories");
str.AppendLine();
str.AppendLine("Electronics");

The following is the complete code −

Example

 Live Demo

using System;
using System.Text;

class Demo {
   static void Main() {
      StringBuilder str = new StringBuilder();
      str.AppendLine("Accessories");
      str.AppendLine();
      str.AppendLine("Electronics");
      Console.Write(str);
   }
}

Output

Accessories

Electronics

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 22-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements