Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Sort the words in lexicographical order in C#
Firstly, set a string array −
string[] arr = new string[] {
"Indian",
"Moroccon",
"American",
};
To sort the words in lexicographical order −
var sort = from a in arr orderby a select a;
Example
Let us see the complete code −
using System;
using System.Linq;
class Program {
static void Main() {
string[] arr = new string[] {
"Indian",
"Moroccon",
"American",
};
var sort = from a in arr
orderby a
select a;
foreach(string res in sort) {
Console.WriteLine(res);
}
}
}
output
American Indian Moroccon
Advertisements
