Skip to main content
8 events
when toggle format what by license comment
Jun 10, 2018 at 14:38 vote accept PaRaXeRoX
Jun 5, 2018 at 6:23 comment added user33306 @t3chb0t - By chaining the OrderBy and ThenBy you will create a custom sort for whatever weight you put on each property.motorcycles.OrderBy(m => m.Speed).ThenBy(m => m.Price).ThenBy(m => m.Weight).ThenBy(m => m.Name)
Jun 5, 2018 at 6:16 comment added t3chb0t How do you mean the properties themselves? That's what the IComparar<T> is for. So that you can implement your custom sorting logic.
Jun 5, 2018 at 6:10 comment added user33306 @t3chb0t - That is definitely an option. but, since the OP's question is dealing specifically with a custom sorting algorithm, that, to me would be going kind of astray from the point. Also, wouldn't OrderBy just use the the properties themselves, in whatever order is desired?
Jun 5, 2018 at 6:05 comment added t3chb0t I find each of the switch cases should be it's own class implementing the IComparer<T> interface so that you can easily pass it to OrderBy.
Jun 5, 2018 at 5:31 history edited user33306 CC BY-SA 4.0
Fixed the `GetHashCode` method.
Jun 5, 2018 at 5:20 history edited user33306 CC BY-SA 4.0
Corrected spelling
Jun 5, 2018 at 5:07 history answered user33306 CC BY-SA 4.0