Demonstates using checked keyword to detect an overflow : checked unchecked : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » checked unchecked »

 

Demonstates using checked keyword to detect an overflow









    

// Compile this program with the following command line:
// C:>csc /checked OvrFlow2.cs

    using System;
    public class OvrFlow2
    {
        static public void Main ()
        {
            int large = 2147483647;
            int larger = large;
            unchecked
            {
                ++larger;
                larger *= 2;
            }
            Console.WriteLine ("large = " + large);
            Console.WriteLine ("larger = " + larger);
        }
    }

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» checked unchecked