Search code examples
c#arrayssorting

Is there a shortcut way to return an array sorted in C#


... other than using: Array.Copy(originalArray, newArray) to make a copy of the original one and then using: return Array.Sort (newArray) to get the sorted array -- without changing the original array, of course?


Solution

  • Yes you can use LINQ, then convert back to an array:

    For example:

    return array.OrderBy(o => o.Col).ToArray();