代碼如下: [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); } } }