I've got a nice riddle in C# (I'm kind of starter). I need to recursively reserve a string (within a method). I've tried:
public static void ReverseString(string str)
{
if(str.Length > 0)
{
char ch = str[str.Length-1];
ReverseString(str.Substring(0,str.Length-2));
Console.Write(ch);
}
}
But it doesn't work.
I'm allowed to change only the text in the 2 first lines of the if.
(the str[str.Length-1] and str.Substring(0,str.Length-2))
What's my mistake? thanks