Over a million developers have joined DZone.

How To Sort String Array Using LINQ In C#

·
A 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
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}