How to initialize a list with a range of numbers in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main() {
        var list = new List<int>(Enumerable.Range(5, 10));
        
        Console.WriteLine(string.Join(" ", list));
    }
}
  
  
  
/*
run:
  
5 6 7 8 9 10 11 12 13 14
  
*/

 



answered Dec 12, 2021 by avibootz
...