Read an input from console and convert to integer
using System;
public class MainClass
{
public static void Main()
{
int newInteger = 0;
try
{
newInteger = System.Convert.ToInt32(System.Console.ReadLine());
}
catch (System.ArgumentNullException)
{
System.Console.WriteLine("String is null.");
}
catch (System.FormatException)
{
System.Console.WriteLine("FormatException");
}
catch (System.OverflowException)
{
System.Console.WriteLine("Overflow");
}
System.Console.WriteLine("Your integer as a double is {0}", System.Convert.ToDouble(newInteger));
}
}
Related examples in the same category