I have a List<string>
of sizes, say XS, S, M, L, XL, XXL, UK 10, UK 12 etc
What I want is to force the order to be that of above, regardless of the order of items in the list, I think I need a IComparable operator but unsure.
Ideally I want to have another List with the correct order in which it can reference it's 'place' in the list and re-sort itself, if it doesn't exist it will default to A-Z
You can use
OrderByDescending
+ThenByDescending
directly:I use
...Descending
since atrue
is similar to 1 whereas afalse
is 0.You could also do something like this:
Usage:
It should also default to A-Z for values not in the list...
You can also create other list, and use a delegate to use with the sort, where you return if the index of size1 > index of size2.
Create an array of sizes in the order you want them to be in, then sort the shirts by the position of their sizes in that array: