zoukankan      html  css  js  c++  java
  • <21天学通C#>使用unchecked使得命令编辑器不对代码进行检查,使用checked对代码进行检查

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace 使用unchecked使得命令编辑器不对代码进行检查
    {
    class Program
    {
    static void Main(string[] args)
    {
    int val1 = 2147483647;
    int val2 ;
    unchecked
    {
    val2 = val1 + 1;
    }
    Console.WriteLine("val1 is {0}", val1);
    Console.WriteLine("val2 is {0}", val2);
    Console.WriteLine("按任意键退出");
    Console.ReadKey();
    }
    }
    }

    改为checked:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace 使用unchecked使得命令编辑器不对代码进行检查
    {
    class Program
    {
    static void Main(string[] args)
    {
    int val1 = 2147483647;
    int val2 ;
    checked
    {
    val2 = val1 + 1;
    }
    Console.WriteLine("val1 is {0}", val1);
    Console.WriteLine("val2 is {0}", val2);
    Console.WriteLine("按任意键退出");
    Console.ReadKey();
    }
    }
    }

     

  • 相关阅读:
    Exercise02_09
    Exercise02_05
    Exercise02_01
    Exercise02_03
    Exercise02_07
    web.xml配置详解
    面对不成功的人生
    请不以结婚为目的的恋爱吧
    年轻人能为世界做点什么
    不作就不会活
  • 原文地址:https://www.cnblogs.com/nnty/p/9929050.html
Copyright © 2011-2022 走看看