How can I sort an array?

  • Thread starter Thread starter Tobias Froehlich
  • Start date Start date
T

Tobias Froehlich

How can I sort an array so that the highest value has the index of 0 ?

I mean if i have a double array like this:

{ 0.1, 0.5, 0.32, 0.9 }

it should be transformed into a new array that looks like the
following::

{ 0.9, 0.5, 0.32, 0.1 }


Thanks in advance!
 
Tobias Froehlich said:
How can I sort an array so that the highest value has the index of 0 ?

I mean if i have a double array like this:

{ 0.1, 0.5, 0.32, 0.9 }

it should be transformed into a new array that looks like the
following::

{ 0.9, 0.5, 0.32, 0.1 }

Either use Array.Sort and then reverse it from the increasing order
you'll get out of it, or use Array.Sort and specify the comparator to
use. The former *may* be significantly faster for large arrays, as the
framework could optimise sorting arrays of primitives so that they
didn't need to be boxed/unboxed for each comparison.
 
Thanks, i'll try it out.

How fast it works is not an issue since it is for an array with only
10 entries.
 
Back
Top