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

This is a C# Program to display the greatest numbers in an array using where clause linq.

Problem Description

This C# Program Displays the Greatest numbers in an Array using WHERE Clause LINQ.

Problem Solution

Here the where clause is used in a query expression to specify which elements from the data source will be returned in the query expression

Program/Source Code

Here is source code of the C# Program to Display the Greatest numbers in an Array using WHERE Clause LINQ. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  C# Program to Display 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 Program
{
    static void Main()
    {
        int[] numbers = { 500, 344, 221, 4443, 229, 1008, 6000, 767, 256, 0 };
        var greaterNums =
            from num in numbers
            where num > 500
            select num;
        Console.WriteLine("Numbers Greater than 500 :");
        foreach (var s in greaterNums)
        {
            Console.Write(s.ToString() + " ");
        }
        Console.Read();
    }
}
Program Explanation

This C# program is used to print the greatest numbers in an array using WHERE clause LINQ. We have already defined the values of ‘array[]’ variable. The where clause is used in a query expression to specify which elements from the data source will be returned in the query expression. The foreach() function is used to print the element values greater than 50.

advertisement
advertisement
Runtime Test Cases
 
Numbers Greater than 500 :
4443 1008 6000 767

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.