获取类型的类型

Sal*_*leh 3 c#

我知道我可以System.Type通过使用获得我班级的一个实例GetType()

Point pt = new Point(0, 0);
System.Type ptType = pt.GetType();
Run Code Online (Sandbox Code Playgroud)

但是当我想要System.Type一个类型时,我该怎么办:

System.Type pointType = Point.GetType();
Run Code Online (Sandbox Code Playgroud)

它不起作用,但我怎么能这样做?

Dar*_*rov 15

您可以使用typeof表达式:

System.Type pointType = typeof(Point);
Run Code Online (Sandbox Code Playgroud)

所述的GetType方法用于获取运行时类型,而typeof表达式获得的编译时类型.