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