Cloud Training (Online)

How to fill a string with repeated characters in C# ?

Here’s a small tip on using the string class better .

You can use the string class constructor to fill a string that has all the repeated characters .

For example , assume you want a string with 10 # or * symbols .

One of doing this declaring a string like this

string str = “##########”;

The other easy and best way is to use the string class constructor like below

private void Form1_Load(object sender, EventArgs e)
     string stringSymbols = new string('#', 10);


Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.