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 299 views
1 answer 275 views
1 answer 270 views
1 answer 293 views
1 answer 258 views
1 answer 190 views
...