Repeated Character in a String in C#

How do I repeat a character in a string a given number of times in C#?

In VB and VB.NET, you can use the String(char,count) function to produce a given character a certain number of times. There is a similar solution in C#.

Just create the string using the constructor shown below:

using System;
using System.Collections.Generic;
using System.Text;

namespace RepeatedString
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(new String('*', 8));
            Console.ReadLine();
        }
    }
}

Here’s the Microsoft .NET documentation for this approach.

One thought on “Repeated Character in a String in C#

Comments are closed.