how to sort an array in c#
  • how to sort an array in c#
  • 4 Comments sorted by
  • Vote Up0Vote Down atirnaveedatirnaveed
    17.50 Karma Accepted Answer
    int[] arry = { 85, 0, 56, 84, 22, 48, 6 };
    Array.Sort(arry);
  • Me i personally prefer LINQ over traditional way of using arrays.
    With LINQ i can write something like this below:

               var sort = arry.OrderBy(x => x).Select(s => s).Take(4);//normal sort
                var sortdesc = arry.OrderByDescending(x => x).Select(s => s).Take(5); //descending sort
  • You can even use .ThenBy sort for complex operations

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Optimum Creative