代码如下:
[csharp]
using System;
class Unboxing_Test
{
static void Main()
{
int i = 100;
object o = i; // 装箱
try www.2cto.com
{
int j = (int)o; // 取消装箱
System.Console.WriteLine("取消装箱成功.");
}
catch (System.InvalidCastException e)
{
System.Console.WriteLine("{0} 取消装箱异常.", e.Message);
}
}
}