Catch OverflowException Exception

image_pdfimage_print
   
 



using System;
   
class MainClass
{
    public static void Main()
    {
        try
        {
            checked
            {
                int Integer1;
                int Integer2;
                int Sum;
   
                Integer1 = 9999999999;
                Integer2 = 2000000000;
                Sum = Integer1 + Integer2;
            }
        }
        catch(OverflowException)
        {
            Console.WriteLine("A mathematical operation caused an overflow.");
        }
    }
}

           
         
     


Use CultureInfo int ToString method

image_pdfimage_print
   
 


using System;
using System.Globalization;
using System.Threading;

class Program {
    static void Main(string[] args) {
        int val = 1234567890;
        Console.WriteLine(val.ToString("N"));
        Console.WriteLine(val.ToString("N",new CultureInfo("fr-FR")));
        Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
        Console.WriteLine(val.ToString("N"));
    }
}
           
         
     


Using Variables

image_pdfimage_print
   
 
using System;

public class UsingVariables
{
  static void Main(string[] args)
  {
    int MyInt = 12345;
    int MyInt2 = MyInt + 1;
    int MyInt3;

    MyInt3 = My2ndFunction(MyInt2);
  }
  static public int My2ndFunction(int myInt2)
  {
    myInt2 = myInt2 * 2;
    return myInt2;
  }
}