Platinum Partner

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
{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}