Chapter 3. Controlling the Flow, Converting Types, and Handling Exceptions
This chapter is about writing code that makes decisions, repeats blocks of statements, converts between types, and handles errors (known as exceptions). You will also learn about some good places to look for help.
This chapter covers the following topics:
- Selection statements
- Iteration statements
- Casting and converting between types
- Handling exceptions
- Checking for overflow
- Looking for help
Selection statements
Every application needs to be able to select from choices and branch along different code paths. The two selection statements in C# are if
and switch
. You can use if
for all your code but switch
can simplify your code in some common scenarios.
Using Visual Studio 2017
Start ...
Get C# 7 and .NET Core: Modern Cross-Platform Development - Second 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.