Mega Code Archive

 
Categories / C# / Data Types
 

Convert console input to double

using System; using System.Globalization; public class MainClass {    public static void Main()    {       int newInteger = 0;       try {         System.Console.WriteLine("Enter an integer:");         newInteger = System.Convert.ToInt32(System.Console.ReadLine());       }       catch (System.ArgumentNullException) {         System.Console.WriteLine("String is null.");       }       catch (System.FormatException) {         System.Console.WriteLine("wrong format.");       }        catch (System.OverflowException) {         System.Console.WriteLine("Overflow in string to int conversion.");       }       System.Console.WriteLine(System.Convert.ToDouble(newInteger));    } }