Display a string in reverse by using recursion : Method Recursion « Class « C# / CSharp Tutorial






using System; 
  
class RevStr { 
 
  public void displayRev(string str) { 
    if(str.Length > 0)  
      displayRev(str.Substring(1, str.Length-1)); 
    else  
      return; 
 
    Console.Write(str[0]); 
  } 
} 
 
class MainClass { 
  public static void Main() {   
    string s = "this is a test"; 
    RevStr rsOb = new RevStr(); 
 
    Console.WriteLine("Original string: " + s); 
 
    Console.Write("Reversed string: "); 
    rsOb.displayRev(s); 
 
    Console.WriteLine(); 
  } 
}
Original string: this is a test
Reversed string: tset a si siht








7.9.Method Recursion
7.9.1.A simple example of recursion.
7.9.2.Display a string in reverse by using recursion
7.9.3.fibonacci in C#
7.9.4.Recursion Count