I have a list:
List<User> users = getUsers();
The User object has 2 properties I want to sort by:
IsActive
Name
Sort first sort by IsActive, and then sort by name.
So the Active Users will be on the top of the list, sorted by name. Then all the in-active users will be listed (sorted alphabetically).
Is this possible or do I have to break the list up and then merge them?
There are less than 100 items in this List, so performance isn’t really an issue.
Simply use
OrderByandThenBy. Thanks to Tim Schmelter for his remark. If you useOrderBy, you will get the user withIsActive == falseat the top of your list.Remember to add to your
usingdirectives: