×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# - Generate numbers that are multiples of 5 using LINQ Parallel Query

Learn, how to generate numbers that are multiples of 5 using the LINQ parallel query in C#? By Nidhi Last updated : April 01, 2023

Generating numbers multiples of 5

In this program, we will generate random numbers that are multiples of 5 using LINQ parallel query, here we will put a condition to check number is multiple of 5 or not in the specified range. Here we used range 1 to 20.

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

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.

C# LINQ Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.