
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Append to StringBuilder in C#
The Append() method add content to a StringBuilder.
Set a String −
StringBuilder str = new StringBuilder();
Now, loop through the number of elements you want and use Append () to append to StringBuilder −
for (int j = 0; j < 5; j++) { str.Append(j).Append(" "); }
The following is the complete code −
Example
using System; using System.Text; class Program { static void Main() { StringBuilder str = new StringBuilder(); for (int j = 0; j < 5; j++) { str.Append(j).Append(" "); } Console.WriteLine(str); } }
Output
0 1 2 3 4
- Related Questions & Answers
- Append to StringBuilder in C# with a new line on the end
- How to use StringBuilder in C#?
- Clear a StringBuilder in C#
- How to create the StringBuilder in C#?
- Access a character in C# StringBuilder
- Default value of StringBuilder in C#
- Iterating C# StringBuilder in a foreach loop
- Difference between String and StringBuilder in C#
- Creating StringBuilder having specified capacity in C#
- Converting String to StringBuilder in Java
- How to find the length of the StringBuilder in C#?
- How to find the MaxCapacity of a StringBuilder in C#?
- How to find the Capacity of a StringBuilder in C#
- Java StringBuilder class.
- Converting a StringBuilder to String in Java
Advertisements