I have a list of 100 elements, which are looking something like that:
- dog
- cat (2)
- bird (34)
- cat + dog (11)
- dog (5)
Additionally I have a specific required order, lets say:
string[] order = {"dog", "bird", "cat", "cat + dog"};
I need my method to sort by aforementioned order and then by numbers, to get as a result:
- dog
- dog (5)
- bird (34)
- cat (2)
- cat + dog (11)
Currently i have something like that:
bool equal = collection
.OrderBy(i => Array.IndexOf(order, i.Split('(').First()))
.ThenBy(i => i.Split('(').Last().Replace(")", " "))
.SequenceEqual(collection2);
But it doesn't work. ThenBy
overlaps first sorting.
Also upon entering int.Parse
to the ThenBy
brackets i'm getting an exception.
Help me to achieve this.