Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C# Program to Print the Numbers Greater Than 786 in an Integer Array using LINQ

  • Last Updated : 18 Oct, 2021

Language-Integrated Query (LINQ) is a uniform query syntax in C# to retrieve data from different sources. It eliminates the mismatch between programming languages and databases and also provides a single querying interface for different types of data sources. In this article, we will learn how to display numbers greater than 786 in an array using LINQ.

Example: 

Input: 1, 234, 456, 678, 789, 987, 654, 345
Output: 789, 987 

Input: 3, 134, 856, 578, 789, 187, 854, 945
Output: 856, 854, 945

Approach: 

To print the numbers greater than 786 in an integer array we use the following approach: 

  • Store integer(input) in an array.
  • By using the LINQ query we will store the numbers greater than 786 in an iterator.
  • Now the iterator is iterated and the integers are printed.

Example:

C#




// C# program to display the numbers greater than 786 in
// an integer array using LINQ
using System;
using System.Linq;
  
class GFG{
      
static void Main()
{
      
    // Input
    int[] Arr = { 1, 234, 456, 678, 789, 987, 654, 345 };
      
    // From the array the numbers greater than 786 are
    // stored in to the iterater numbers.
    var numbers = from number in Arr where number > 786 select number;
      
    // Display the output
    Console.WriteLine("The numbers larger than 786 are :");
    foreach(int n in numbers)
    {
        Console.Write(n + " ");
    }
}
}

Output:

The numbers larger than 786 are :
789 987 
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!