zoukankan      html  css  js  c++  java
  • typeof与GetType

    typeof: The typeof operator is used to obtain the System.Type object for a type.

     

    运算符,获得某一类型的 System.Type 对象。

     

    Type t = typeof(int);

     

     

     

    GetType: Gets the Type of the current instance.

     

                方法,获取当前实例的类型

     

                 int i = 10;
    Console.WriteLine(i.GetType());

     

     

    区别:

     

      • Typeof()是运算符而GetType是方法
      • GetType()是基类System.Object的方法,因此只有建立一个实例之后才能够被调用(初始化以后)
      • Typeof()的参数只能是int,string,String,自定义类型,且不能是实例

         

      • GetType() typeof()都返回System.Type的引用。

         

        TypeOf() 和GetType()的区别:  

        (1)TypeOf():得到一个Class的Type

        (2)GetType():得到一个Class的实例的Type

        override 一个方法的前担是这个方法在父类中:abstract or  virtual, override

  • 相关阅读:
    关于程序收到消息的顺序
    窗口过程
    消息循环
    解剖窗口程序
    开始了解窗口程序
    编码的规范
    汇编的除法和乘法
    Win32汇编--Win32汇编的高级语法
    H5-音频列表音乐切换
    移动端-ibokan
  • 原文地址:https://www.cnblogs.com/newsouls/p/4229130.html
Copyright © 2011-2022 走看看