I need a basic example of how to use the IComparable interface so that I can sort in ascending or descending order and by different fields of the object type I’m sorting.
I need a basic example of how to use the IComparable interface so that
Share
Well, since you are using
List<T>it would be a lot simpler to just use aComparison<T>, for example:Of course, with LINQ you could just use:
But you can re-introduce this in
List<T>(for in-place re-ordering) quite easily; Here’s an example that allowsSortonList<T>with lambda syntax: