Polymorphism

noun

say it: “pol-ee-MOR-fiz-um” /ˌpɒliˈmɔːrfɪzəm/

Using one type, such as a base class or interface, to work with objects that each behave their own way.

What is Polymorphism in C#?

Polymorphism — Using one declared type to work with objects that provide different implementations.

class Alert
{
    public virtual string Text()
    {
        return "Alert";
    }
}

class EmailAlert : Alert
{
    public override string Text()
    {
        return "Email";
    }
}

In a sentence

  • “Thanks to polymorphism, one foreach over List<Shape> draws circles and squares correctly.”

Level: Journeyman · More C# terms at this level

Updated

In other subjects