ch3_06.cs
来自「《c#技术内幕代码》」· CS 代码 · 共 34 行
CS
34 行
using System;
public class CH3_6
{
public int CheckedAddition( short s1, short s2)
{
int z = 0;
try
{
z = checked((short)(s1 + s2));
}
catch ( OverflowException )
{
Console.WriteLine("Overflow Exception, Returning 0");
}
return z;
}
public int UncheckedAddition( short s1, short s2 )
{
int z = ((short)(s1 + s2));
return z;
}
public static void Main()
{
CH3_6 app = new CH3_6();
short s1 = 32767;
short s2 = 32767;
Console.WriteLine("Checked Addition is: {0}", app.CheckedAddition(s1,s2));
Console.WriteLine("Unchecked Addition is: {0}", app.UncheckedAddition(s1,s2));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?