Convert long to integer and catch the OverflowException : OverflowException « Data Types « C# / C Sharp






Convert long to integer and catch the OverflowException

 

using System;
using System.Globalization;

public class Example
{
    public static void Main()
    {


        long lNumber = 111111111111111;
        try
        {
            int number1 = (int)lNumber;
            Console.WriteLine(number1);
        }
        catch (OverflowException)
        {
            Console.WriteLine("{0} is out of range of an Int32.", lNumber);
        }
    }
}

   
  








Related examples in the same category

1.Convert double to integer and catch OverflowException