#847 – How the Call Stack Works

A call stack is an indication of which method in your application is currently executing and how the application got there.  When a method is called, information about that method is pushed onto the call stack.  When the method returns to its caller, that information is popped back off the stack.  In this way, the top of the stack always refers to the current method.  And, traversing down the stack, we see the sequence of calls that got us to the current method.

For example, assume that when your application starts, a Main method is called.  Information about Main is pushed onto the stack.


Assume that Main then creates an instance of a Dog object and calls its BarkYourAge method.


If BarkYourAge then calls method DogUtil.GenerateBark, we get:


When control returns from GenerateBark, we continue in the BarkYourAge method and the stack becomes: