Reverse a string (without built-in reverse)?
Logic
- Convert to char array.
- Swap characters from both ends.
string str = "dotnet";
char[] chars = str.ToCharArray();
int left = 0, right = chars.Length - 1;
while (left < right)
{
char temp = chars[left];
chars[left] = chars[right];
chars[right] = temp;
left++;
right--;
}
string reversed = new string(chars);