Users Online

· Guests Online: 64

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

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

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.

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

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.90 seconds
10,844,558 unique visits