Saleh
Saleh

Reputation: 3032

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 does not work, but how can I do this?

Upvotes: 3

Views: 289

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

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.

Upvotes: 15

Related Questions