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

Published on February 12, 2016 by abundantcode

Filed under C#

Last modified February 11, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 4143 times

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();
        }
       

    } 
}

3 Comments

  1. Json.NET & C# – Installing Json.NET for C# projects in Visual Studio 2015 | Abundant Code
    February 13, 2016 - 4:03 pm

  2. Json.NET & Oxygene – Installing Json.NET for Remobjects Oxygene projects in Visual Studio 2015 | Abundant Code
    March 13, 2016 - 3:39 pm

  3. Json.NET & VB.NET – Installing Json.NET for VB.NET projects in Visual Studio 2015 | Abundant Code
    April 13, 2016 - 3:47 pm

Leave a Comment


x

You might be Interested in these Posts

C Program to find the G.C.D of a number using Recursive function

Problem Write a program in C to find the find the G.C.D of a number using recursion and display the ...

C Program to print a Half Pyramid using *

Problem Write a program in C to print Half pyramid using * as shown. * * * * * * * * * * ...

C Program to display Positive factors of a number

Problem Write a program in C to display all the positive factors of a number enter by the user. Ho...