How to repeat a string N times into an array using Linq in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        string s = "c#";

        int N = 3;
        var arr = from w in Enumerable.Repeat(s, N)
                    select w;

        foreach (string str in arr)
            Console.WriteLine(str);
    }
}



/*
run:

c#
c#
c#

*/

 



answered Mar 10, 2021 by avibootz

Related questions

1 answer 223 views
1 answer 186 views
1 answer 188 views
1 answer 206 views
1 answer 168 views
1 answer 154 views
...