class CheckedDemo
{
static void Main()
{
byte a, b;
byte result;
a = 127;
b = 127;
try
{
result = (byte)(a * b);
}
catch (OverflowException exc)
{
Console.WriteLine(exc);
}
Console.WriteLine(result);
}
}
总是报:使用了未赋值的局部变量“result” 错误
如果改成 result=checked((byte)(a*b));
或者 result=unchecked((byte)(a*b));
就没有错误了。
请问为什么???