Implement Simple Recursion - CSharp Custom Type

CSharp examples for Custom Type:Method

Description

Implement Simple Recursion

Demo Code

using System;//from   w  w  w  .j ava 2  s  .  co  m
class TestRecursive
{
   public static void Main()
   {
      Recurs(3);
   }
   public static void Recurs(int level)
   {
      Console.WriteLine("First part of Recurs. Level: {0}", level);
      if (level == 1)
         return;
      else
         Recurs(level - 1);
      Console.WriteLine("Last part of Recurs.  Level: {0}", level);
   }
}

Result


Related Tutorials