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/*  w  w  w  .  j  a  va 2 s .  c  om*/
{
    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