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.
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.
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.
Output:
Explanation:
In the above program, we created a Program class that contains the Main() method.
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.