Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 917
Alexander Popov Avatar asked Nov 19 '12 15:11

Alexander Popov


2 Answers

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.

like image 70
Tim Schmelter Avatar answered Oct 22 '22 16:10

Tim Schmelter


You can use one of the 'string' constructors, like so:

Console.WriteLine(new string('.', 10));
like image 39
Dan Puzey Avatar answered Oct 22 '22 14:10

Dan Puzey