Reputation: 21621
To get the type of a class called myClass I do this
Type myType = (typeof(myClass))
How about, instead of having myClass, I've rather the instanceOfMyClass? How do I get the type?
Let's say I've this
Contact contact = new Contact();
If I want to know which type is contact, how do I do it
Thanks for helping
Upvotes: 1
Views: 82
Reputation: 6805
If I've read this correctly, you can get the run-time type of the object via:
Contact contact = new Contact();
Type contactType = contact.GetType();
Upvotes: 2
Reputation: 57658
You use contact.GetType();
method. The GetType
is defined in the Object
class so is available globally.
Upvotes: 4