Exiting Methods

Ordinarily, code within a method executes from beginning to end—literally. However, when a return statement is reached, execution immediately returns to the statement that made the method call; you can force execution to leave the method at any time by using a return statement. If C# encounters a return statement, the method terminates immediately, and code returns to the statement that called the method.

As you build your applications, you'll find that the number of methods and classes expands rather quickly. At times, you'll realize that a method isn't finished or that you had to use a “hack” (a less-desirable solution) to solve a problem. You'll need an easy way to keep these things straight so that you can revisit the code ...

Get Sams Teach Yourself C#™ in 24 Hours 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.