List has an overload of the Sort() method, which accepts an instance of IComparer<T> . the interface is quite simple to implement and will allow you to sort in any way you want:
public class MantissaComparer : IComparer<double> { public int Compare(double x, double y) { return Comparer<double>.Default.Compare(x - Math.Truncate(x), y - Math.Truncate(y)); } }
Then use a custom comparator as follows:
input.Sort(new MantissaComparer());
I see the linq tag, but this solution is used more than once in the whole code if you deem it necessary, while avoiding over-engineering due to the simple IComparer interface.
source share