[Solved] C# List sorting with multiple range


you can use the Sort overload accepting a Comparison.
This should work:

public static int MyCompare(double x, double y)
{
    if (x >= 0.0 == y>=0.0)
        // same sign, compare by absolute value
        return Math.Abs(x).CompareTo(Math.Abs(y));

    if (x < 0.0)
        return 1;

    return -1;
}

usage:

var list = new List<double>();
// fill your list
// call sort using the Comparison

// hard syntax
//list.Sort((x,y) => MyCompare(x, y));

// easy syntax :)
list.Sort(MyCompare);

foreach (var x in list)
    Console.WriteLine(x);

see it at work: https://dotnetfiddle.net/odOJYh

0

solved C# List sorting with multiple range