One of the most important features of the CLR is its type safety. At run time, the CLR always knows what type an object is. You can always discover an object’s exact type by calling the
GetType method. Because this method is nonvirtual, it is impossible for a type to spoof another type. For example, the
Employee type can’t override the
GetType method and have it return a type of
Developers frequently find it necessary to cast an object to various types. The CLR allows you to cast an object to its type or to any of its base types. Your programming language of choice decides how to expose casting operations to the developer. For example, C# doesn’t require any special syntax to cast an object to any of its base ...