c# sort array of strings code example
Example 1: c# sort array string by length
public static string[] SortLength(string[] arr)
{
string[] sorted = arr
.OrderBy(x => x.Length) //.OrderByDescending
.ToArray();
return sorted;
}
Example 2: how to sort string array alphabetically in c#
Array.Sort(names, (x,y) => String.Compare(x.Name, y.Name));
Example 3: c# sort array
Array.Sort(arr);