获取类型的类型
我知道我可以使用GetType()
获取我的类实例的System.Type
Point pt = new Point(0, 0); System.Type ptType = pt.GetType();
但是当我想要获得类型的System.Type
时我该怎么办:
System.Type pointType = Point.GetType();
它不起作用,但我怎么能这样做?
您可以使用typeof表达式:
System.Type pointType = typeof(Point);
GetType方法用于获取运行时类型,而typeof
表达式用于获取编译时类型。