i have an object that has a string property called “Status”. I have a collection of these objects and want to order a collection by that field which is a string.
the possible values of Status are:
“Open”, “Closed”, “Pending” so i can’t use alphabetic order. What is the best way to say that “Open” is greater than “Closed” which is greater than “Pending” ?
I know there is an IComparer<> interface but i want to see the most elegant way to define the order of various strings.
How about using an Enum instead of a string?
Then Open > Closed > Pending
You can also use Jon Skeet’s answer to convert your string to an enum, if you can’t change the fact that you’re returning string.