Section III

Program Statements

The lessons in Section II focused on working with variables. They explained how to declare variables, set their values, and perform calculations.

Those techniques let you do some fairly complex things, but they're still relatively straightforward things that you could do yourself by hand if you really had to. For example, you could easily calculate line item totals, sales tax, shipping, and a grand total for a purchase order.

With what you know so far, you really can't write a program that takes full advantage of the computer's power. You can't make the program add up an unknown number of values stored in a ListBox, perform the same task (such as calculating an account balance) for thousands of customers, or take different actions depending on the user's inputs. You can't even write a program that can tell if the user entered an invalid value such as “seventy-eight” in a TextBox that should contain a number.

The lessons in this section explain how to perform these kinds of tasks. They explain ways you can make a program take different courses of action depending on circumstances, repeat a set of actions many times, break code into manageable pieces to make it easier to write and debug, and handle unexpected errors. After you finish reading these lessons, you'll be able to write applications that are much more powerful than those you can write now.

Get C# 24-Hour Trainer, 2nd Edition 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.