CSharp - LINQ Range

Introduction

The Range operator generates a sequence of integers.

Prototypes

public static IEnumerable<int> Range(
        int start,
        int count);

A sequence of integers will be generated starting from start and continuing for the number of count.

Range is not an extension method. It is a static method called on System.Linq.Enumerable.

Exceptions

ArgumentOutOfRangeException is thrown if the count is less than zero or if start plus count minus one is greater than int.MaxValue.

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program/*from ww w  .  j  a  v  a  2 s  .com*/
{
    static void Main(string[] args)
    {
        IEnumerable<int> ints = Enumerable.Range(1, 10);
        foreach(int i in ints)
            Console.WriteLine(i);
    }
}

Result