Advertisement
Guest User

Untitled

a guest
May 11th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. namespace Recursion
  5. {
  6.     class Program
  7.     {
  8.         static void test1(ref int i)
  9.         {
  10.             i++;
  11.             if (i > 5)
  12.             {
  13.                 return;
  14.             }
  15.             Debug.WriteLine(string.Format("Before {0}", i));
  16.             test1(ref i);
  17.             Debug.WriteLine(string.Format("After {0}", i));
  18.         }
  19.  
  20.         static void test2(int i)
  21.         {
  22.             i++;
  23.             if (i > 5)
  24.             {
  25.                 return;
  26.             }
  27.             Debug.WriteLine(string.Format("Before {0}", i));
  28.             test2(i);
  29.             Debug.WriteLine(string.Format("After {0}", i));
  30.         }
  31.  
  32.         static void Main(string[] args)
  33.         {
  34.             int i = 0;
  35.             test1(ref i);
  36.             Debug.WriteLine(string.Empty);
  37.             test2(0);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement