CSharp - Repeat for PLINQ

Introduction

The Repeat operator creates a ParallelQuery<T> that contains a single value of type T repeated a specified number of times.

Repeat operator is a static method in the ParallelEnumerable class, rather than an extension method operator.

Prototypes

public static ParallelQuery<T> Repeat<T>(
          T element,
          int count
)

The Repeat method takes two arguments.

The first is the element that you want to repeat.

The second is the number of times that the element should be repeated in the sequence.

The following code demonstrates creating a repeating sequence using the Repeat method.

We create a sequence where the integer value 2 is repeated 10 times.

Using a foreach loop, we enumerate the sequence and print out each element in the sequence.

Demo

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

class Program//  www  .  java2s  .c  o m
{
    static void Main(string[] args)
    {
          ParallelQuery<int> pq = ParallelEnumerable.Repeat(2, 10);
    
          foreach (int i in pq) {
              Console.WriteLine("Value {0}", i);
          }
    }
}

Result