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 do you sort an array in C# in ascending order?
Firstly, set the unsorted array.
int[] list = {98, 23, 97, 36, 77};
Sort the array using the Sort() method.
Array.Sort(list);
You can try to run the following code to to sort an array in ascending 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 + " ");
}
Array.Sort(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 23 36 77 97 98
Advertisements