GetType() on a class w/o instantiate an object

Z

Zeng

Hello,

I'm just wondering if we somehow we can obtain the System.Type of a class
w/o instantiating an object of the class.

Right now I have to do this and it doesn't seem efficient, type is a static
information, why would we need to instantiate an object of the class?

MyObject = new MyClass();
System.Type = MyObject.GetType();

thanks!
 
J

Jon Skeet [C# MVP]

Zeng said:
I'm just wondering if we somehow we can obtain the System.Type of a class
w/o instantiating an object of the class.

Right now I have to do this and it doesn't seem efficient, type is a static
information, why would we need to instantiate an object of the class?

MyObject = new MyClass();
System.Type = MyObject.GetType();

Use the typeof operator:

Type t = typeof(MyClass);
 
L

Lecture Snoddddgrass

Brother Zeng,

Walk down the path of "typeof()" ... he will show you the way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top