Get Type Of a Type
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开发者_如何学C 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.
精彩评论