How to initialize an array with N sequential integers in C#

1 Answer

0 votes
using System;
using System.Linq;

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



/*
run:

5
6
7
8
9
10
11

*/

 



answered Nov 26, 2020 by avibootz
...