LINQ Range Operator

By Peter Bromberg

The Range operator generates a sequence of integral numbers.


// Example generates a range starting at 10, for 20 elements.
using System;
using System.Linq;

namespace LinqSample
{
    public class RangeExample
    {
         public static void Main()
        {
             var numbers = Enumerable.Range(10, 20);
             
             foreach (int x in numbers)
            {
               Console.WriteLine(x);
            }
            
           Console.ReadLine();
        }
    }
}

Output:

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

LINQ Range Operator  (625 Views)