代码如下:

[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);  
        }  
    }  
}  
 
posted on 2015-01-29 09:03  GC2013  阅读(439)  评论(1编辑  收藏  举报