Skip to content
Related Articles
Open in App
Not now

Related Articles

C# Program to Find Greatest Numbers in an Array using WHERE Clause LINQ

Improve Article
Save Article
  • Last Updated : 18 Oct, 2021
Improve Article
Save Article

LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matter which type of data source is used. In this article, we will learn how to find the greatest numbers in an array using WHERE Clause LINQ. Here, we will get the numbers that are greater than a particular number in the given array.


Input: Array of Integers: 100,200,300,450,324,56,77,890
Value: 500
Output: Numbers greater than 500 are: 890
Input: Array of Integers: 34,56,78,100,200,300,450,324,56,77,890
Value: 100
Output: Numbers greater than 100 are: 200,300,450,324,890


To display the greatest numbers in an array using WHERE Clause LINQ follow the following approach:

  1. Store integer(input) in an array.
  2. The sum of the elements is calculated using the for loop.
  3. The numbers which are greater than particular value is checked using where function.
  4. By using the LINQ query we will store the numbers in an iterator.
  5. Now the iterator is iterated and the integers are printed.



// C# program to print the greatest numbers in an array
// using WHERE Clause LINQ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class GFG{
static void Main()
    // Array of numbers
    int[] array1 = { 34, 56, 78, 100, 200, 300,
                     450, 324, 56, 77, 890 };
    // Now get the numbers greater than 100 and 
    // store in big variable using where clause
    var big = from value in array1 where value > 100 select value;
    Console.WriteLine("Numbers that are greater than 100 are  :");
    // Get the greater numbers
    foreach (var s in big)
        Console.Write(s.ToString() + " ");


Numbers that are greater than 100 are  :
200 300 450 324 890 
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!