I have a string array like this:
string[] names = new string[] { "john", "paul", "ringo", "george", "janis" };
I want to sort this array using a custom criteria. It can’t be alphabetical. It might be in this order: pgrj.
I’ve tried to implement a new IComparer, but inside the Compare() method I can’t use string.Compare cause it would sort alphabetically and I don’t want to do that.
The question is: How can I sort the names array in this order: pgrj ? In the ‘j’ case. Janis might be before John.
Thanks.
I would make an array of the letters of the alphabet, in the order that they should be sorted. Let’s call this array
sort. You could then do something likeNow a few disclaimers.
You could improve on this by making a custom class to assign a weight to each character.
From here you can sum of the value for each letter of a string and do the comparison that way. It might be a little more complex than your situation requires