How to: class / type name

E

Eric

Is there an easy way to get a string representation? Wasn't apparent to me
from looking at the reflection class.

Thanks,
Eric
 
J

Jon Shemitz

Eric said:
Is there an easy way to get a string representation? Wasn't apparent to me
from looking at the reflection class.

Of a type's name? The Type.Name property or Type.FullName is probably
what you want.

You get a runtime Type instance from typeof(ClassName) or
ClassInstance.GetType().
 
D

Dave Sexton

Hi Eric,

Type type = typeof(System.Object); // Type known at design-time

string name = type.FullName;
// System.Object

string qualified = type.AssemblyQualifiedName;
// System.Object, mscorlib, Version=2.0.0.0, Culture=neutral,
// PublicKeyToken=b77a5c561934e089

or

// Type unknown at design-time
Type type = objAnyInstance.GetType();
 

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