List.Sort (Custom sorting...)
Ok, I know this is a few years old but I have an alternative solution that I think is more elegant than the above solutions that future readers might want to consider:
In your class:
static readonly List<String> codeValueSortOrder = new List<String> {
"Full To H",
"Partial",
"Full To O"
};
and in your method:
sortedList = list.OrderBy(i=> codeValueSortOrder.IndexOf(i.CodeValue));
Linq is great for this. You could even build the order sequence up to have it defined on the fly since the execution of the sort is not executed until the ToList
.
var sortedList = yourList.OrderBy(i => i.FullToH).
ThenBy(i => i.Partial).
ThenBy(i => i.FullToO).ToList();