reverse a string in c# without reverseing charcetr code example
Example 1: reverse string c#
string str = "Hello World!"; // the string which you want to reverse
string reverse = "";
int length = str.Length - 1;
while(length >= 0)
{
reverse += str[length];
length--;
}
Console.WriteLine(reverse); // output: "!dlroW olleH"
Example 2: reverse a string in c#
public void ReverseString(char[] s) {
for(int i = 0; i < s.Length / 2; i++) {
char temp = s[i];
s[i] = s[s.Length - 1 - i];
s[s.Length - 1 - i] = temp;
}
}