ADVERTISEMENT
ADVERTISEMENT

C# program to demonstrate the use of Linq OrderByDescending() method

Here, we are going to learn about the Linq OrderByDescending() method and its C# implementation.
Submitted by Nidhi, on August 29, 2020

Here we will create a list of integer values and then sort them in descending order using the OrderByDescending() method.

Program:

The source code to demonstrate the use of the Linq OrderBuDescending() method, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the use of 
//Linq OrderByDescending() method.

using System;
using System.Linq;
using System.Collections.Generic;

class Demo
{
    static void Main(string[] args)
    {
        List<int> list = new List<int>() { 49, 34, 13, 56, 25, 65 };

        var result = list.OrderByDescending(num => num);

        Console.WriteLine("Sorted list in Descending order:");
        foreach (int value in result)
        {
            Console.Write(value + " ");
        }
        Console.WriteLine();
    }
}

Output:

Sorted list in Descending order:
65 56 49 34 25 13
Press any key to continue . . .

Explanation:

In the above program, we created a Demo class that contains the Main() method to start the execution of the program. In the main() method we created the list of integers and then we sort them using the OrderByDescending() method using the below code.

Then we printed the filtered values on the console screen.

C# LINQ Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.