首页 > Windows开发 > 详细

c# GetType()和typeof()的区别

时间:2019-02-08 17:32:21      阅读:210      评论:0      收藏:0      [点我收藏+]

c#   GetType()和typeof()的区别

 

C#中任何对象都具有GetType()方法返回Type类型的当前对象的类型。

GetType()是基类System.Object的方法,因此只有建立一个实例之后才能够被调用。

typeof(x)中的x,必须是具体的类名、类型名称等,不可以是变量名称;

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

  1. typeof的参数只能是int,string,String,自定义类型,且不能是实例
  2. GetType()和typeof都返回System.Type的引用.
  3. typeof():得到一个Class的Type
  4. GetType():得到一个Class的实例的Type

c# GetType()和typeof()的区别

原文:https://www.cnblogs.com/GoldenEllipsis/p/10356404.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!