Bad Data

Line: Input Line
Easy Difficulty Input Learning Outcome One Walkthrough
Type: Walkthrough
You should have completed:

Temperature Conversion

This topic leads to:

Verification

Summary

So far, if a user has typed in information in a format the program was not expecting, it has crashed our programs. There is a robust approach to error handling within C# but we will cover it later in the module. In the meantime, there is an approach which will help reduce the number of crashes due to incorrect user input.

Task

  1. Open your program from the Getting Numbers exercise.
  2. Instead of using Int32.Parse to convert the user input to a number, use the following.
    Code Snippet

Questions

  1. Why is there an 'out' keyword there?
  2. How would you use the same technique to get a float or double value from the user?