CSharp - Ranges and Repetitions

Introduction

You can generate sequence using the static Range method from the System.Linq.ParallelEnumerable class.

The following code demonstrates how to create the sequence.

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program/*  ww  w  .j  a v a2s  . c o m*/
{
    static void Main(string[] args)
    {
           IEnumerable<int> evens
              = ((ParallelQuery<int>) ParallelEnumerable.Range(0, 50000))
               .Where(i => i % 2 == 0)
               .Select(i => i);
    }
}

The code uses the Range method to create a sequence of 50,000 integers starting with the zero.

The first argument to the method is the start index; the second is the number of values you require.

We have cast the result from the Range method to a ParallelQuery<int>.

Related Topics