What is polymorphism in C#?

Answer

Polymorphism (many forms) allows objects of different types to be treated as objects of a common type, with each type responding differently to the same message. In C#: Compile-time polymorphism (static dispatch): method overloading — multiple methods with the same name but different parameter lists. The compiler selects the correct one. Runtime polymorphism (dynamic dispatch): method overriding — a derived class overrides a virtual or abstract method. The correct method is selected at runtime based on the actual type. Example: Animal a = new Dog(); a.Speak(); — calls Dog.Speak() if overridden, even though the variable is typed as Animal. This requires virtual dispatch. Interface polymorphism: different types implementing the same interface can be used interchangeably. Polymorphism is the foundation of the Open/Closed Principle.