How to initialize an array the same number in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        int[] arr = Enumerable.Repeat(5, 10).ToArray();
        
        foreach (int n in arr) {
            Console.WriteLine(n);
        }
    }
}



/*
run:

5
5
5
5
5
5
5
5
5
5

*/

 



answered Nov 26, 2020 by avibootz
...