 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
C# Program to order array elements
Use ThenBy() method to order array elements. Let’s say we have the following string array.
string[] str = { "Sandler", "Jack", "Tom", "Matt", "Henry", "Johnny" }; Now, use Lambda Expressions and set a condition inside the ThenBy() method to sort the strings according to the number of characters they have.
IEnumerable<string> res = str.AsQueryable().OrderBy(alp => alp.Length).ThenBy(alp => alp);
Here is the entire example to order array elements using ThenBy() method.
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       string[] str = { "Sandler", "Jack", "Tom", "Matt", "Henry", "Johnny" };       IEnumerable<string> res = str.AsQueryable().OrderBy(alp => alp.Length).ThenBy(alp => alp);       foreach (string arr in res)       Console.WriteLine(arr);    } }  Output
Tom Jack Matt Henry Johnny Sandler
Advertisements
 