Pending Method Instances of Different Methods

To understand how recursion works, it is important to first understand the mechanics of chains of method calls. Listing 23.1 does not contain any recursive method calls and does not solve any particular problem, it merely demonstrates what happens when one method calls a second method that calls a third method that calls a fourth method.

Listing 23.1. MethodCallDemo.cs
 01: using System; 02: 03: class MethodCallDemo 04: { 05: public static void Main() 06: { 07: MethodA(3); 08: } 09: 10: public static void MethodA(int level) 11: { 12: Console.WriteLine("First part of MethodA. Level: { 0} ", level); 13: MethodB(level - 1); 14: Console.WriteLine("Last part of MethodA. Level: { 0} ", level); 15: return; ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.