The return Statement

In a world where method calls are one of the most essential ways to structure code, we need two core concepts: One is to call a method, using invocation syntax, as you saw when we discussed expressions; the other is a way to return from a method, transferring control back to the caller. Intimately related to this is the concept of a call stack as a means to keep track of who’s called what. Figure 7.29 shows the transitions of the call stack when making a method call and returning a result.

Image

FIGURE 7.29 Illustrating the call stack.

The return statement has two forms. When used in a procedure—a method that returns the magical ...

Get C# 5.0 Unleashed 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.