111,097
社区成员




public static int Sum(int a, int b)
{
int sumTotal;
try
{
sumTotal = checked(a + b);
}
catch (OverflowException)
{
sumTotal = -1; // 当求和溢出时,能不能返回一个特殊值进行提示,如“Error”
}
return sumTotal;
}
// 改成这样的了
public static int? Sum(int a, int b)
{
int? sumTotal;
try
{
sumTotal = checked(a + b);
}
catch (OverflowException)
{
sumTotal = null;
}
return sumTotal;
}
public static int Sum(int a, int b, out string msg)
{
int sumTotal;
try
{
sumTotal = checked(a + b);
msg="OK";
}
catch (OverflowException)
{
msg="Error";
sumTotal = -1; // 当求和溢出时,能不能返回一个特殊值进行提示,如“Error”
}
return sumTotal;
}