Making Decisions and Branching Code

You can use the operators discussed previously to test for specific conditions in your code. These tests are then evaluated in order to make a decision on what code to execute or where to branch off in your application. There are three primary decision structures in .NET programming: If...Then...Else, Select...Case, and Try...Catch...Finally (covered in the “Handling Errors” section later in the chapter).

If...Then...Else

You can use the If syntax in your code to test one or more conditions. Based on the results of your test, you might decide to execute one set of code if the condition proves true and another set of code if the condition proves false. You can also get into more complex scenarios by nesting ...

Get Microsoft® Visual Studio® 2010 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.