object.GetType

  • Thread starter Thread starter web1110
  • Start date Start date
W

web1110

Hi y'all,

I am not entirely clear on how to use this method, object.GetType.
Actually, I'm quite in the dark. For what can it be used?

Given an object, is this used to promote the object to a derived class?

As an aside, how is this done? For instance, given any object as a generic
object, how do I discover its derived class and convert it to that type of
class.

Thanx,
Bill
 
Bill,

GetType() returns the current 'most derived' type of the object. you
can use that method to find out the type of any object, which is
quite helpful in a lot of circumstances.

you don't need to 'discover' the derived classes type: GetType()
will return that type.

WM_HOPETHISHELPS
thomas woelfer
http://www.die.de/blog
 
Could you give me a simple minded example. The question arose when I tried
this and couldn't get a successful compilation. This led me to think I was
following the wrong path.

By the way, thanks
Bill
 
You asked: " For instance, given any object as a generic
object, how do I discover its derived class and convert it to that type of
class."

In many cases discovering derived classes is not the best way because it
creates tight coupling between classes. Class hierarchies and interfaces
should be designed in such a way that it is transparent to the caller what
exact subtype is called.

Leonid Finis.
 
I understand. I am curious as to how to accomplish this,nothing more. I
don't foresee a need, just a lack of knowledge.
 
Back
Top