How to repeat a string N number of times in C# ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Do you want to repeat a string N number of times in C# ? . You can use the string.concat and Enumerable.Repeat to achieve it in .NET Framework 4.0 and higher.

How to repeat a string N number of times in C# ?

using System;
using System.Linq;

namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = 4; 
            var result = string.Concat(Enumerable.Repeat("Abundantcode", X));
            Console.WriteLine(result);
            Console.ReadLine();
        }
       

    } 
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: