Jsut for an explanation, because every time you delete a character, you increase the counter i, but also decrease charList.Count, so you actually delete 1 character, leaving the next one, then deleting it again, etc.
For example, when you enter "string ...." and x is 5 (the index of the letter G), which you do:
1st iteration: Remove g char so x becomes 6 and charList.Count becomes 9 (10-1)
Next iteration: Remove the char with index 6, which is now second. (your string is "strin ... ...").
So, you missed the first point.
I let you check other answers as they contain more elegant solutions to your problems.
source share