Sort a string array alphabetically with order by clause in CSharp
Description
The following code shows how to sort a string array alphabetically with order by clause.
Example
using System;/*from w w w. ja va2 s . c om*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
string[] words = { "C", "a", "b" };
var sortedWords =
from w in words
orderby w
select w;
Console.WriteLine("The sorted list of words:");
foreach (var w in sortedWords) {
Console.WriteLine(w);
}
}
}
The code above generates the following result.