📄 4-9.txt
字号:
using System;
class Test
{
static int x = 1000000;
static int y = 1000000;
static int F() { return checked(x*y); }
static int G() { return unchecked(x*y); }
static int H() { return x*y; }
public static void Main()
{ //F(); //G(); //H(); }
}
F();
未处理的“System.OverflowException”类型的异常出现在 4-9.exe 中。
其他信息: 算术运算导致溢出。
G();
H();
通过编译。
--------------------------------------------------------------------------------------------------------------------
using System;
class Test
{
const int x = 1000000;
const int y = 1000000;
static int F( ) { return checked(x*y); }
static int G( ) { return unchecked(x*y); }
static int H( ) { return x*y; }
public static void Main( )
{ //F( ); //G( ); //H( ); }
}
F( );
在检查模式下,运算在编译时溢出
G( );
通过编译
H( );
在检查模式下,运算在编译时溢出
-------------------------------------------------------------------------------------------------------------------
using System;
class Test
{
static int F(int x, int y) { return x*y; }
static int G( )
{ return checked(F(1000000,1000000)); }
public static void Main( )
{ G( ); }
}
注:只对F( )进行检测,不会影响函数F方法中的x*y运算。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -