Reputation: 1103
Below is the order of the Data that I get in the list object from other service.
How can I sort the order of above list in the below order?
Level 0 Class
Level 0 S-Class
Level 1 Class
Level 1 S-Class
Level 2 Class
Level 2 S-Class
Level 0 Lesson
Level 0 S-Lesson
Level 1 Lesson
Level 1 S-Lesson
Level 2 Lesson
Level 2 S-Lesson
So far I have tried as below, but only getting the right order for ProgramId "E".
myList.OrderByDescending(x => x.ProgramId== "E")
.ThenBy(x => x.Level)
.ThenBy(x => x.Special = True)
.ThenBy(x => x.Special = False)
.ThenByDescending(x => x.ProgramId== "B")
.ThenBy(x => x.Level)
.ThenBy(x => x.Special = True)
.ThenBy(x => x.Special = False);
Below is the sorting logic that I am trying to apply:
Any help suggestion on this would be appreciated!
Upvotes: 2
Views: 179
Reputation: 48435
This will produce the order you have requested:
myList = myList.OrderByDescending(x => x.ProgramId)
.ThenBy(x => x.Level)
.ThenBy(x => x.Special);
I have no idea why you think this doesn't work, but I have now tested it and it works exactly to your specification.
Upvotes: 1
Reputation: 13626
try this?
myList.OrderByDescending(x => x.ProgramId)
.ThenBy(x => x.Level)
.ThenByDescending(x => x.Special)
Upvotes: 3