Mega Code Archive

 
Categories / C# / Data Types
 

Convert double to integer and catch OverflowException

using System; using System.Globalization; public class Example {     public static void Main()     {         double dbl2 = 1111111111.999;         try         {             int number2 = (int)dbl2;             Console.WriteLine(number2);         }         catch (OverflowException)         {             Console.WriteLine("{0} is out of range of an Int32.", dbl2);         }     } }