http://www.cnblogs.com/limingluzhu/archive/2011/11/07/2239130.html
checked 关键字用于对整型算术运算和转换显式启用溢出检查。
默认情况下,如果表达式仅包含常数值,且产生的值在目标类型范围之外,则它会导致编译器错误。 如果表达式包含一个或多个非常数值,则编译器不检测溢出。 在下面的示例中,计算赋给 i2 的表达式不会导致编译器错误。
// The following example causes compiler error CS0220 because 2147483647
// is the maximum value for integers.
//int i1 = 2147483647 + 10;
// The following example, which includes variable ten, does not cause
// a compiler error.
int
ten = 10;
int
i2 = 2147483647 + ten;
// By default, the overflow in the previous statement also does
// not cause a run-time exception. The following line displays
// -2,147,483,639 as the sum of 2,147,483,647 and 10.
Console.WriteLine(i2);
|
默认情况下,在运行时也不检查这些非常数表达式是否溢出,这些表达式不引发溢出异常。 上面的示例显示 -2,147,483,639 作为两个正整数之和。
可以通过编译器选项、环境配置或使用 checked 关键字来启用溢出检查。 下面的示例演示如何使用 checked 表达式或 checked 块,在运行时检测由前面的求和计算导致的溢出。 两个示例都引发溢出异常。
// If the previous sum is attempted in a checked environment, an // OverflowException error is raised. // Checked expression. Console.WriteLine(checked(2147483647 + ten)); // Checked block. checked { int i3 = 2147483647 + ten; Console.WriteLine(i3); }
可以使用unchecked取消溢出检查
此示例演示如何使用 checked 启用运行时溢出检查。
class OverFlowTest { // Set maxIntValue to the maximum value for integers. static int maxIntValue = 2147483647; // Using a checked expression. static int CheckedMethod() { int z = 0; try { // The following line raises an exception because it is checked. z = checked(maxIntValue + 10); } catch (System.OverflowException e) { // The following line displays information about the error. Console.WriteLine("CHECKED and CAUGHT: " + e.ToString()); } // The value of z is still 0. return z; } // Using an unchecked expression. static int UncheckedMethod() { int z = 0; try { // The following calculation is unchecked and will not // raise an exception. z = maxIntValue + 10; } catch (System.OverflowException e) { // The following line will not be executed. Console.WriteLine("UNCHECKED and CAUGHT: " + e.ToString()); } // Because of the undetected overflow, the sum of 2147483647 + 10 is // returned as -2147483639. return z; } static void Main() { Console.WriteLine("\nCHECKED output value is: {0}", CheckedMethod()); Console.WriteLine("UNCHECKED output value is: {0}", UncheckedMethod()); } /* Output: CHECKED and CAUGHT: System.OverflowException: Arithmetic operation resulted in an overflow. at ConsoleApplication1.OverFlowTest.CheckedMethod() CHECKED output value is: 0 UNCHECKED output value is: -2147483639 */ }
介绍内存与CPU的连接_1671465600
Vue同步异步存值取值的方法发布时间:2020-08-10 11:20:35来源:亿速云阅读:126作者:小新Vue同步异步存值取值的方法?这个问题可能是我们日常学习或工作经常见到的。希望通过这个问题能让你收获颇深。下面是小编给大家带来的参考内容,让我们一起来看看吧!1.vue中各个组件之间传值1.父子组件父组件–>子组件,通过子组件的自定义属性:props子组件–>父组件,通过自定义...
//方式一:在for-each循环中使用entries来遍历System.out.println("方式一:在for-each循环中使用entries来遍历");for(Map.Entry entry: map.entrySet()) {System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());}..._1671465600
动态规划:数字金字塔#include<iostream>using namespace std;int a[101][101];//int dfs(int m,int n){//}int main(){ int i,j,m; cin>>m; for(i=0;i<m;i++){ for(j=0;j<=i;j++){ cin>&...
最近项目中使用了RxJava2+ Retrofit2框架,框架基本都是统一封装HttpBean,使用map操作符转化数据,然后根据code码的逻辑去处理业务,开发过程中遇到一个问题,服务器返回的json数据格式为{"code": 200, "data": null, "message": null}, 发现客户端竟然报错解析不了。。。附上之前写的代码:public class RxFun...
这篇文章主要介绍了Python函数重载,通过文字和代码两者结合讲解,希望对大家学习有一定的帮助。什么是函数重载?简单的理解,支持多个同名函数的定义,只是参数的个数或者类型不同,在调用的时候,解释器会根据参数的个数或者类型,调用相应的函数。重载这个特性在很多语言中都有实现,比如 C++、Java 等,而 Python 并不支持。这篇文章呢,通过一些小技巧,可以让 Python 支持类似的功能。参数个数不同的情形先看看这种情况下 C++ 是怎么实现重载的#include <iostream>
可以达到文字描一圈黑边的效果:继承UILabel以后重载drawTextInRect:- (void)drawTextInRect:(CGRect)rect { CGSize shadowOffset = self.shadowOffset; UIColor *textColor = self.textColor; CGContextRef c = UIGra...
安装flask遇到cannot import name 'escape' from 'jinja2' 的问题及解决办法
from:http://blog.csdn.net/AlicePeter/article/details/3862059刚刚解决的问题:wince 5中用EVC 写应用程序自己调用显示忙状态的沙漏.我发的相关帖子的地址:http://topic.csdn.net/u/20090203/09/1b4bda94-deea-4b62-b78b-4739bbd5167e.html第一种情况
写在文章前面的话:“工欲行其事,必先利其器”,英雄和侠客更需要宝剑助己成功。同样,在现代软件开发环境中,每个Android开发者都需要更好的工具,帮助我们增强功能、提高效率。在这个竞争激烈的行业中,只有优秀的工程师能够生存,需要我们能够为客户提供的最佳技术和资源,需要有优秀的开发工具,保证以最佳质量以及高效时间来构建。工作了十来个年头,也经常给内部培训,以及面试下应聘者。内训是最好的提升自己公司地位的过程,同时也会让你更快的接触上层老板。有个朴素的逻辑,你给他赚到了钱,足以惊动到他注意,这
LightOJ 1197 Help Hanzo题意:给定[L,R],问[L,R]内有多少个素数数据范围L,R<=231,R-L<=1e5code:#include<bits/stdc++.h>using namespace std;#define int long longconst int maxm=1e5+5;int notprime[maxm];//...