I have a List of messages. Each message has a type.
public enum MessageType { Foo = 0, Bar = 1, Boo = 2, Doo = 3 }
The enum
An alternative to using IComparer would be to build an ordering dictionary.
IComparer
var orderMap = new Dictionary() { { MessageType.Boo, 0 }, { MessageType.Bar, 1 }, { MessageType.Foo, 2 }, { MessageType.Doo, 3 } }; var orderedList = messageList.OrderBy(m => orderMap[m.MessageType]);