Polymorphism the C# meaning

Through inheritence a class can be more then one type and this is referred to as polymorphism. Within C# all types are polymorphic, because it treats every type as an Object.

The Microsoft definition is as follows:
“Through inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. This is called polymorphism. In C#, every type is polymorphic. Types can be used as their own type or as a Object instance, because any type automatically treats Object as a base type.

Polymorphism is important not only to the derived classes, but to the base classes as well. Anyone using the base class could, in fact, be using an object of the derived class that has been cast to the base class type. Designers of a base class can anticipate the aspects of their base class that are likely to change for a derived type. For example, a base class for cars might contain behavior that is subject to change when the car in question is a minivan or a convertible. A base class can mark those class members as virtual, allowing derived classes representing convertibles and minivans to override that behavior.”

The basic “meaning” by the above statement is all C# types are derived from System.Object which allows them to be “morphed” into any type.

Leave a Reply