How to print the same character many times with Console.WriteLine()

Alexander picture Alexander · Nov 19, 2012 · Viewed 26k times · Source

Possible Duplicate:
Is there an easy way to return a string repeated X number of times?

If I want to display a dot 10 times in Python, I could either use this:

print ".........."

or this

print "." * 10

How do I use the second method in C#? I tried variations of:

Console.WriteLine("."*10);

but none of them worked. Thanks.

Answer

Tim Schmelter picture Tim Schmelter · Nov 19, 2012

You can use the string constructor:

Console.WriteLine(new string('.', 10));

Initializes a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times.