Q:

C# program to generate numbers that are multiples of 5 using the LINQ parallel query

0

C# program to generate numbers that are multiples of 5 using the LINQ parallel query

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to generate numbers that are multiples of 5 using the LINQ parallel query in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to generate numbers that are 
//multiples of 5 using LINQ parallel query.

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

class Program
{
    static void Main(string[] args)
    {
        IEnumerable<int> Numbers = ((ParallelQuery<int>)ParallelEnumerable.Range(1,30))
        .Where(num => num%5==0)
        .Select(val => val);

        foreach (int num in Numbers) 
        {
            Console.WriteLine(num); 
        }
    }
}

Output:

5
10
20
25
15
30
Press any key to continue . . .

Explanation:

In the above program, we created a Program class that contains the Main() method.

IEnumerable Numbers = ((ParallelQuery)ParallelEnumerable.Range(1,30))
.Where(num => num%5==0)
.Select(val => val);

Here we created integer numbers collection of IEnumerable type. Here we generated numbers that are multiples of 5. Then we printed the random numbers between the range 1 to 50 on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now