Is there a way to order a collection by two properties? For example:
I have a PriorityProcess
class, and I want to order a collection of these instances by priority
(descending) and then arrival time
(ascending), but I want this last sort not to overwrite the previous one, more like a sub-sort.
Suppose I have this array of processes:
- P0 -> Priority = 1, Arrival Time = 0
- P1 -> Priority = 2, Arrival Time = 3
- P2 -> Priority = 1, Arrival Time = 8
- P3 -> Priority = 3, Arrival Time = 16
I would like to sort it, so I end up with this:
- P3 -> Priority = 3, Arrival Time = 16
- P1 -> Priority = 2, Arrival Time = 3
- P0 -> Priority = 1, Arrival Time = 0
- P2 -> Priority = 1, Arrival Time = 8
Is there a way to accomplish this in a single LINQ instruction?
Thanks for your time