In the last section you learned how to retrieve an object's Type using either the GetType() function or the typeof construct. If you have two variables and you want to know if they point to the same type you could always get their Type objects and check their Name property. However, GetType() only reports the type of the object and not whether the object is compatible with another type. For example if a class called MotherInLaw is derived from ExtendedFamily , which is derived from Person , which is derived from System.Object then an object of MotherInLaw is compatible with variables of type MotherInLaw , ExtendedFamily , Person (yes, mothers-in-law are persons) and object . What's more, if a variable of type object points to an instance of MotherInLaw , just from looking at the variable it's impossible to tell whether a variable of type Person could point to the same object or not. To test if an object is compatible with a type:
Tips
|