Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
We’ve seen that you can cast from a type to one of its ancestors or an interface it implements by using the CType() function (or one of the dedicated conversion functions):
CType(oldType, NewType)
We’ve also seen that the Object.GetType() method (inherited by every type in the .NET Framework) returns an instance of the Type class, so you can do something like this to check whether two objects are of the same type:
If MyStandardRecipe.GetType() = MyRecipe.GetType()
This test certainly has its place, but it compares the types of two objects, and it’s an absolute test. What if you wanted to test whether an object is a certain type but don’t have an instance of that type lying around? You could use the Name property of the Type object returned by GetType():