unchecked operator

To disable the overflow checking for certain expression, use the unchecked operator.


using System;

class Program
{
    static void Main(string[] args)
    {
        int i = int.MinValue;

        unchecked {
            int result = i - 1;

            Console.WriteLine("i=" + i);

            Console.WriteLine("result=" + result);
            Console.WriteLine("result is int.MaxValue:" + (result == int.MaxValue));
        }
    }
}

The output:


i=-2147483648
result=2147483647
result is int.MaxValue:True
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.