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 the best 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, also known as if-else and switch-case. You can use if for all your code but switch can simplify your code in some common scenarios. ...

Get C# 6 and .NET Core 1.0: Modern Cross-Platform Development 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.