
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- How do you sort an array in C# in descending order?
- C program to sort an array in an ascending order
- Golang Program To Sort An Array In Ascending Order Using Insertion Sort
- 8086 program to sort an integer array in ascending order
- Java Program to Sort Array list in an Ascending Order
- How to sort Java array elements in ascending order?
- How to sort an ArrayList in Ascending Order in Java
- How to sort an ArrayList in Java in ascending order?
- C program to sort an array of ten elements in an ascending order
- Python program to sort the elements of an array in ascending order
- Golang Program To Sort The Elements Of An Array In Ascending Order
- Swift Program to Sort the Elements of an Array in Ascending Order
- C++ Program to Sort the Elements of an Array in Ascending Order
- How to perform ascending order sort in MongoDB?
- How to sort one-dimensional array in ascending order using non-static method?

Advertisements