Sort String Array using LINQ

Madhu.b.rokkam
Posted by Madhu.b.rokkam under C# category on | Points: 40 | Views : 2613
static void Main(string[] args)
{
string[] data = { "Ram", "Shyam", "Gopal" };

List<string> sortedData = new List<string>(data);
sortedData.Sort((string a, string b) =>
{
return a.CompareTo(b);
});

Console.WriteLine(string.Join(",", sortedData.ToArray()));
Console.Read();
}


Result

Gopal,Ram,Shyam

Comments or Responses

Login to post response