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

  • Thread starter Thread starter Zeng
  • Start date Start date
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!
 
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);
 
Brother Zeng,

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