typeof,gettype,is,as

   public class testclass
    {
        public string s = "";
        public int i = 0;
    }

 

    testclass o = new testclass();

    System.Type t1 = typeof(testclass);
    System.Type t2 = o.GetType();

    if (o is testclass)
    {
        MessageBox.Show("o is testclass");
    }

     object b = o as object;
     if(b.GetType() is System.Type)
     {
          MessageBox.Show("b.GetType() is testclass");
     }

 

typeof(类型)得到System.Type

实例.gettype()得到System.Type

is: if(实例 is 类型)

as 转型


posted on 2008-09-02 16:43  优雅小猪  阅读(461)  评论(0编辑  收藏  举报

导航