c# sort string array 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);
Example 4: c# sort array
int[] sortedCopy = from element in copyArray
orderby element ascending select element;