Q:

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

belongs to collection: C# LINQ Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# LINQ Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to sort student names in descending ord... >>
<< C# program to demonstrate the example of Linq Inte...