Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to sort one dimensional array in descending order using Array Class method?
The following is the unsorted array.
int[] list = {98, 23, 97, 36, 77};
Now first use the Sort() method to sort the array.
Array.Reverse(list);
Use the Reverse() method that would eventually give you a sorted array in descending order.
Array.Reverse(list);
You can try to run the following code to to sort one dimensional array in descending order.
Example
using System;
namespace Demo {
public class MyApplication {
public static void Main(string[] args) {
int[] list = {98, 23, 97, 36, 77};
Console.WriteLine("Original Unsorted List");
foreach (int i in list) {
Console.Write(i + " ");
}
//sort
Array.Sort(list);
// Descending order
Array.Reverse(list);
Console.WriteLine("
Sorted List");
for(int i=0; i<list.Length; i++) {
Console.Write(list[i] + " ");
}
}
}
}
Output
Original Unsorted List 98 23 97 36 77 Sorted List 98 97 77 36 23
Advertisements