How to use Enumerable.Repeat() to create an array with repeated elements in C#

1 Answer

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = Enumerable.Repeat(3, 5);

            foreach (int n in numbers)
                Console.WriteLine(n);
        }
    }
}


/*
run:

3
3
3
3
3

*/

 



answered Mar 4, 2017 by avibootz

Related questions

...