
- 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
C# Program to order array elements in descending order
To orders elements in a sequence in descending order, use ThenBy() and OrderByDescending.
This is our string array.
string[] myStr = { "Keyboard", "Laptop", "Mouse", "Monitor" };
Now, use OrderByDescending to order element in Descending order. Inside that calculate the length of each string and use Lambda Expressions as well.
IEnumerable<string> res = myStr.AsQueryable().OrderByDescending(ch => ch.Length).ThenBy(ch => ch);
The following is the example discussed above.
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] myStr = { "Keyboard", "Laptop", "Mouse", "Monitor" }; IEnumerable<string> res = myStr.AsQueryable().OrderByDescending(ch => ch.Length).ThenBy(ch => ch); foreach (string arr in res) Console.WriteLine(arr); } }
Output
Keyboard Monitor Laptop Mouse
- Related Articles
- C++ Program to Sort the Elements of an Array in Descending Order
- Java Program to Sort the Array Elements in Descending Order
- C# program to sort an array in descending order
- C program to sort an array in descending order
- Python program to sort the elements of an array in descending order
- Swift Program to Sort the Elements of an Array in Descending Order
- Golang Program To Sort The Elements Of An Array In Descending Order
- C# Program to order array elements
- Sort list elements in descending order in C#
- 8086 program to sort an integer array in descending order
- Sort an array in descending order using C#
- C++ Program to Sort Elements in Lexicographical Order (Dictionary Order)
- Traverse TreeSet elements in descending order in java
- Golang Program to sort an array in descending order using insertion sort
- Swift Program to sort an array in descending order using bubble sort

Advertisements