How To Sort String Array Using LINQ In C#
Join the DZone community and get the full member experience.
Join For FreeA string[] array and use a LINQ query expression to order its contents alphabetically. Note that we are ordering the strings, not the letters in the strings.
using System;
using System.Linq;
class Program
{
static void Main()
{
string[] a = new string[] {"Indonesian","Korean","Japanese","English","German"};
var sort = from s in a orderby s select s;
foreach (string c in sort)
{
Console.WriteLine(c);
}
}
}
/*OUTPUT
English
German
Indonesian
Japanese
Korean
*/
Eclipse IDE and Eclipse
Strings
Sort (Unix)
Data structure
Data Types
Opinions expressed by DZone contributors are their own.
Comments