How can the Array elements be sorted in descending order in c# dotnet
Loading
How can the Array elements be sorted in descending order in c# dotnet
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jul 6, 2025, 2:13 AM EDT
Yes using Array.Sort() and then call Array. Reverse() method
Jainil Patel7 reputationPosted Jul 8, 2025, 12:06 AM EDT
To sort an array in descending order in C# (.NET), you can use the built-in
Array.Sort()method along withArray.Reverse()for a more concise approach.Using
Array.Sort()andArray.Reverse()int[] numbers = { 5, 2, 9, 1, 7 }; // Step 1: Sort in ascending order Array.Sort(numbers); // Step 2: Reverse to get descending order Array.Reverse(numbers); // Output foreach (int num in numbers) { Console.Write(num + " "); }Jignesh KumarRank #91 · 22.9K reputationPosted Jul 8, 2025, 11:37 PM EDT
Hello Kiran,
There are multiple ways we can sort an Array,
Array.Sort()and then Reverseint[] numbers = { 5, 2, 9, 1, 7 }; Array.Sort(numbers); // First, sort in ascending order using in-built method Array.Reverse(numbers); // Then reverse to get descending orderint[] numbers = { 5, 2, 9, 1, 7 }; int[] descending = numbers.OrderByDescending(n => n).ToArray(); // Sorted in descending order using OrderByDescending() method or linq