C# checked unchecked

static void CheckedUnCheckedDemo()
        {
            int i = int.MaxValue;
            try
            {
                //checked
                //{
                //    Console.WriteLine(i + 1);
                //}
                unchecked
                {
                    Console.WriteLine(i + 1);
                }
            }
            catch(OverflowException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

 

你可能感兴趣的:(C# checked unchecked)