title: Float/Double type input validation in C#
body: <p>This is literally my first program I've ever written (started learning this past Monday); I am a total newbie. </p>
  
  <p>My question is, how can I prevent exceptions from being thrown when a user enters an invalid character when the program prompts the user for fahreinheit or celsius entry (expecting a number)??? So for example, when a user enters "asfasd", the program throws an exception. </p>
  
  <p>I did a lot of searching on the site before posting this, and I was successfully able to find other input validation questions, however, they were all concerning C and C++ and since I am such a newbie, I have a hard time with understanding those languages and how they relate to C#. Thank you. Please see code:</p>
  
  <pre><code>using System;
  
  
  namespace Converter
  {
  class Program
  {
      static void Main()
      {
          float? FahrenheitInput = null;
          double? CelsiusInput = null;
          float? KilogramInput = null;
          float? PoundsInput = null;
          int UserChoice = 0;
          do
          {
  
              Console.WriteLine("What would you like to convert? Enter the corresponding number.\n1. Fahrenheit to Celsius");
              Console.WriteLine("2. Celsius to Fahrenheit\n3. Pounds to Kilograms\n4. Kilograms to pounds\n5. Exit program");
              UserChoice = int.Parse(Console.ReadLine());
              switch (UserChoice)
              {
                  case 1:
                      Console.WriteLine("Enter the temperature in Fahreinheit, number only:");
                      FahrenheitInput = float.Parse(Console.ReadLine());
                      Console.Clear();
                      Console.WriteLine(FahrenheitInput + " degrees fahrenheit in Celsius is " + Program.FahrenheitToCelsius(FahrenheitInput) + "\n\n");
                      break;
                  case 2:
                      Console.WriteLine("Enter the temperature in Celsius, number only:");
                      CelsiusInput = double.Parse(Console.ReadLine());
                      Console.Clear();
                      Console.WriteLine(CelsiusInput + " degrees Celius in fahrenheit is " + Program.CelsiusToFahrenheit(CelsiusInput) + "\n\n");
                      break;
                  case 5:
                      break;
                  default:
                      Console.WriteLine("This is not a valid entry. Please enter 1, 2, 3, 4, or 5.");
                      break;
  
              }
          } while (UserChoice != 5);
  
  
      }
      public static float? FahrenheitToCelsius(float? INPUT)
      {
          return (INPUT - 32) * 5 / 9;
      }
      public static double? CelsiusToFahrenheit(double? INPUT)
      {
          return INPUT * 1.8 + 32;
      }
  }
  </code></pre>
  
  <p>}</p>