I want to sort a list based on 3 numeric conditions. I need to do this sorting based on the property called 'CompletionPercentage'. So the list should be sorted on below conditions
- Filter the list where the percentage should be greater than
0and less than100 - Next filter the list where the percentage is equal to
0 - Next filter the list where the percentage is equal to
100
I have tried the below code but it is not working. Please help.
var data = myCollection
.ToList()
.Where(x => getCourses.CourseLevel.Contains(x.CourseLevel)
.OrderBy(x => x.CompletionPercentage > 1 && x.CompletionPercentage < 99)
.ThenBy(x => x.CompletionPercentage == 0)
.ThenBy(x => x.CompletionPercentage == 100);
OrderByandThenByare sorting operations, not filtering. If by filtering you mean "sorting", you might want to implement a customIComparer. Can you clarify exactly what you want, perhaps with a worked example?