获取型A型 [英] Get Type Of a Type
本文介绍了获取型A型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我能得到一个 系统。类型
我的类的实例中使用的 的GetType()
点角=新点(0,0);
System.Type的ptType = pt.GetType();
不过,我可以做的,当我想要得到什么的System.Type
A型:
的System.Type pointType = Point.GetType();
它不工作,但我怎么能这样做呢?
< DIV CLASS =h2_lin>解决方案
您可以使用的typeof 表达式:
的System.Type pointType = typeof运算(点);
的
的GetType 方法被用于获取运行时类型,而的typeof
表达式获得编译时类型。
I know I can get a System.Type
of an instance of my class by using GetType()
Point pt = new Point(0, 0);
System.Type ptType = pt.GetType();
But what can I do when I want get System.Type
of a type:
System.Type pointType = Point.GetType();
It does not work, but how can I do this?
解决方案
You could use the typeof expression:
System.Type pointType = typeof(Point);
The GetType method is used to get the runtime type, whereas the typeof
expression gets the compile-time type.
这篇关于获取型A型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文