Song Lee

Song Lee

  • NA
  • 47
  • 37.3k

if,return method

Oct 17 2014 3:12 PM
 Hi, I was wondering if there a way to make it so if something other than int or double is input, it gives an error message.
This is what I got so far: 
 
public static void FirstInput()
{
Console.WriteLine("F to C");
Console.Write("Enter number : ");
double.TryParse(Console.ReadLine(), out fromF);
}
 
//and below is the coding that I got from a friend 
Is there a way to integrate those two codes? 

if (int.tryParse(Console.ReadLine(), out res))

return res;

console.WriteLine("Error, can't convert, try again");

return GetInteger();

 
 
Thank you! 
 

Answers (2)